From d604dad8e3dc6bd2e9aeb65ee43fa356ec6a2952 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Wed, 20 Dec 2023 14:54:01 +0530 Subject: [PATCH] Update publisher sample code with ability to provide payload as an env-variable --- examples/kafka-hub/publisher/main.bal | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/kafka-hub/publisher/main.bal b/examples/kafka-hub/publisher/main.bal index a796578d..99fdbb0c 100644 --- a/examples/kafka-hub/publisher/main.bal +++ b/examples/kafka-hub/publisher/main.bal @@ -18,7 +18,16 @@ import ballerina/websubhub; import ballerina/io; import ballerina/os; -string topicName = os:getEnv("TOPIC_NAME") == "" ? "priceUpdate" : os:getEnv("TOPIC_NAME"); +json DEFAULT_PAYLOAD = { + itemName: string `Panasonic 32" LED TV`, + itemCode: "ITM30029", + previousPrice: 32999.00, + newPrice: 28999.00, + currencyCode: "SEK" +}; + +final string topicName = os:getEnv("TOPIC_NAME") == "" ? "priceUpdate" : os:getEnv("TOPIC_NAME"); +final json payload = os:getEnv("PAYLOAD") == "" ? DEFAULT_PAYLOAD: check os:getEnv("PAYLOAD").fromJsonString(); type OAuth2Config record {| string tokenUrl; @@ -49,13 +58,6 @@ public function main() returns error? { cert: "./resources/server.crt" } ); - json params = { - itemName: string `Panasonic 32" LED TV`, - itemCode: "ITM30029", - previousPrice: 32999.00, - newPrice: 28999.00, - currencyCode: "SEK" - }; - websubhub:Acknowledgement response = check websubHubClientEP->publishUpdate(topicName, params); + websubhub:Acknowledgement response = check websubHubClientEP->publishUpdate(topicName, payload); io:println("Receieved content-publish result: ", response); }