From 2f35ed17820016901275e25eb4fc1c806b81f05f Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Mon, 3 Jun 2024 12:38:56 +0530 Subject: [PATCH] Add quickstart instructions for ASB listener-svc implementation --- README.md | 36 ++++++++++++++++++++++++++++++++++-- ballerina/Module.md | 34 +++++++++++++++++++++++++++++++++- ballerina/Package.md | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e373ec3b..3081bb69 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,23 @@ This can be done by providing a connection string with a queue name, topic name, asb:MessageReceiver asbReceiver = check new (receiverConfig); ``` +#### Initialize a message listener + +This can be done by providing a connection string with a queue name, topic name, or subscription path. + +> Here, the Receive mode is optional. (Default: PEEKLOCK) + +```ballerina + configurable string connectionString = ?; + + listener asb:Listener asbListener = check new ( + connectionString = connectionString, + entityConfig = { + queueName: "myQueue" + } + ); +``` + ### Step 3: Invoke connector operation Now you can use the remote operations available within the connector, @@ -195,7 +212,7 @@ public function main() returns error? { asb:Message|asb:Error? messageReceived = asbReceiver->receive(serverWaitTime); if (messageReceived is asb:Message) { - log:printInfo("Reading Received Message : " + message received.toString()); + log:printInfo("Reading Received Message : " + messageReceived.toString()); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -205,7 +222,22 @@ public function main() returns error? { check asbReceiver->close(); } ``` - + +**Receive messages from Azure service bus using `asb:Service`** + +```ballerina +service asb:Service on asbListener { + + isolated remote function onMessage(asb:Message message) returns error? { + log:printInfo("Reading Received Message : " + message.toString()); + } + + isolated remote function onError(asb:MessageRetrievalError 'error) returns error? { + log:printError("Error occurred while receiving messages from ASB", 'error); + } +} +``` + ### Step 4: Run the Ballerina application ```bash diff --git a/ballerina/Module.md b/ballerina/Module.md index 30001302..75cdc136 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -134,6 +134,23 @@ This can be done by providing a connection string with a queue name, topic name, asb:MessageReceiver receiver = check new (receiverConfig); ``` +#### Initialize a message listener + +This can be done by providing a connection string with a queue name, topic name, or subscription path. + +> Here, the Receive mode is optional. (Default: PEEKLOCK) + +```ballerina + configurable string connectionString = ?; + + listener asb:Listener asbListener = check new ( + connectionString = connectionString, + entityConfig = { + queueName: "myQueue" + } + ); +``` + ### Step 3: Invoke connector operation Now you can use the remote operations available within the connector, @@ -198,7 +215,22 @@ public function main() returns error? { check queueReceiver->close(); } ``` - + +**Receive messages from Azure service bus using `asb:Service`** + +```ballerina +service asb:Service on asbListener { + + isolated remote function onMessage(asb:Message message) returns error? { + log:printInfo("Reading Received Message : " + message.toString()); + } + + isolated remote function onError(asb:MessageRetrievalError 'error) returns error? { + log:printError("Error occurred while receiving messages from ASB", 'error); + } +} +``` + ### Step 4: Run the Ballerina application ```bash diff --git a/ballerina/Package.md b/ballerina/Package.md index 30001302..75cdc136 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -134,6 +134,23 @@ This can be done by providing a connection string with a queue name, topic name, asb:MessageReceiver receiver = check new (receiverConfig); ``` +#### Initialize a message listener + +This can be done by providing a connection string with a queue name, topic name, or subscription path. + +> Here, the Receive mode is optional. (Default: PEEKLOCK) + +```ballerina + configurable string connectionString = ?; + + listener asb:Listener asbListener = check new ( + connectionString = connectionString, + entityConfig = { + queueName: "myQueue" + } + ); +``` + ### Step 3: Invoke connector operation Now you can use the remote operations available within the connector, @@ -198,7 +215,22 @@ public function main() returns error? { check queueReceiver->close(); } ``` - + +**Receive messages from Azure service bus using `asb:Service`** + +```ballerina +service asb:Service on asbListener { + + isolated remote function onMessage(asb:Message message) returns error? { + log:printInfo("Reading Received Message : " + message.toString()); + } + + isolated remote function onError(asb:MessageRetrievalError 'error) returns error? { + log:printError("Error occurred while receiving messages from ASB", 'error); + } +} +``` + ### Step 4: Run the Ballerina application ```bash