diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 287b355f..29707aea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,42 @@ jobs: with: java-version: 11 + - name: 'Create settings.xml' + run: | + echo ' + + github + + + + github + + + central + https://repo1.maven.org/maven2 + true + true + + + github + GitHub ballerina-platform Apache Maven Packages + https://maven.pkg.github.com/ballerina-platform/ballerina-lang + + + + + + + github + ${{ secrets.USERNAME }} + ${{ secrets.PERSONAL_TOKEN }} + + + ' > ~/.m2/settings.xml + - working-directory: ./asb-native run: mvn clean package diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 00004976..a56b68ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,42 @@ jobs: with: java-version: 11 + - name: 'Create settings.xml' + run: | + echo ' + + github + + + + github + + + central + https://repo1.maven.org/maven2 + true + true + + + github + GitHub ballerina-platform Apache Maven Packages + https://maven.pkg.github.com/ballerina-platform/ballerina-lang + + + + + + + github + ${{ secrets.USERNAME }} + ${{ secrets.PERSONAL_TOKEN }} + + + ' > ~/.m2/settings.xml + - working-directory: ./asb-native run: mvn clean package diff --git a/.travis.yml b/.travis.yml index 28070d4f..e249ec2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,10 @@ # limitations under the License. script: - - wget http://dist-dev.ballerina.io/downloads/swan-lake-preview8/ballerina-linux-installer-x64-swan-lake-preview8.deb - - sudo dpkg -i ballerina-linux-installer-x64-swan-lake-preview8.deb + - wget http://dist-dev.ballerina.io/downloads/swan-lake-alpha2/ballerina-linux-installer-x64-swan-lake-alpha2.deb + - sudo dpkg -i ballerina-linux-installer-x64-swan-lake-alpha2.deb - sudo apt-get install -f - export JAVA_OPTS="-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - - ballerina --version + - bal --version - cd asb-native && mvn clean package && cd .. - - ballerina build --skip-tests ./asb-ballerina + - bal build -c --skip-tests ./asb-ballerina diff --git a/README.md b/README.md index e9518a56..9027eddc 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,8 @@ basic operations. These APIs use Shared Access Signature(SAS) authentication and * Java 11 Installed Java Development Kit (JDK) with version 11 is required. -* Ballerina SLP8 Installed - Ballerina Swan Lake Preview Version 8 is required. +* Ballerina SLAlpha2 Installed + Ballerina Swan Lake Alpha 2 is required. * Shared Access Signature (SAS) Authentication Credentials * Connection String @@ -129,7 +129,7 @@ to/from the queue/topic/subscription. ## Supported Versions | | Version | |:-------------------:|:---------------------------:| -| Ballerina Language | Swan-Lake-Preview8 | +| Ballerina Language | Swan-Lake-Alpha2 | | Service Bus API | v1.2.8 | # Quickstart(s) @@ -166,8 +166,8 @@ First, import the ballerinax/asb module into the Ballerina project. You can now make the connection configuration using the connection string and entity path. ```ballerina asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; ``` @@ -275,8 +275,8 @@ First, import the ballerinax/asb module into the Ballerina project. You can now make the connection configuration using the connection string and entity path. ```ballerina asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; ``` @@ -320,8 +320,8 @@ the service logic to execute when a message is received inside the onMessage rem asb:Service asyncTestService = @asb:ServiceConfig { queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") + connectionString: , + queueName: } } service object { @@ -349,7 +349,7 @@ the connection with the Azure Service Bus. checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start listening"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end listening"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -396,8 +396,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -467,8 +467,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -539,8 +539,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -616,23 +616,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -745,23 +745,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -888,8 +888,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -956,8 +956,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1019,23 +1019,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1131,23 +1131,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1244,8 +1244,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1308,23 +1308,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1408,9 +1408,8 @@ Sample is available at: https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/async_consumer.bal ```ballerina -import ballerina/config; import ballerina/log; -import ballerina/runtime; +import ballerina/lang.runtime; import ballerinax/asb; public function main() { @@ -1426,8 +1425,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1444,8 +1443,8 @@ public function main() { asb:Service asyncTestService = @asb:ServiceConfig { queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") + connectionString: , + queueName: } } service object { @@ -1464,7 +1463,7 @@ public function main() { checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start listening"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end listening"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -1503,8 +1502,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1578,8 +1577,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1646,23 +1645,23 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1764,8 +1763,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1855,23 +1854,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -2038,8 +2037,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -2106,23 +2105,23 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -2208,7 +2207,7 @@ public function main() { > **Note:** Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK. -2. Download and install [Ballerina SLP8](https://ballerina.io/). +2. Download and install [Ballerina SLAlpha2](https://ballerina.io/). ### Building the Source diff --git a/asb-ballerina/.gitignore b/asb-ballerina/.gitignore index 6be7938d..9c21c4d5 100644 --- a/asb-ballerina/.gitignore +++ b/asb-ballerina/.gitignore @@ -3,3 +3,4 @@ javalibs ballerina.conf Ballerina.lock modules +Config.toml diff --git a/asb-ballerina/Ballerina.toml b/asb-ballerina/Ballerina.toml index 57325b44..94270df5 100644 --- a/asb-ballerina/Ballerina.toml +++ b/asb-ballerina/Ballerina.toml @@ -1,7 +1,11 @@ [package] org = "ballerinax" name = "asb" -version = "0.1.0" +version = "0.1.1" +license= ["Apache-2.0"] +authors = ["Ballerina"] +keywords = ["Azure","ServiceBus"] +repository = "https://github.com/ballerina-platform/module-ballerinax-azure-service-bus" [build-options] observabilityIncluded = true diff --git a/asb-ballerina/Module.md b/asb-ballerina/Module.md index 39d367f9..3d0d0095 100644 --- a/asb-ballerina/Module.md +++ b/asb-ballerina/Module.md @@ -13,7 +13,7 @@ basic operations. These APIs use SAS authentication and this module supports SAS # Compatibility | | Version | |:-------------------:|:---------------------------:| -| Ballerina Language | Swan-Lake-Preview8 | +| Ballerina Language | Swan-Lake-Alpha2 | | Service Bus API | v1.2.8 | # Supported Operations @@ -56,8 +56,8 @@ immediate stop listening. * Java 11 Installed Java Development Kit (JDK) with version 11 is required. -* Ballerina SLP8 Installed - Ballerina Swan Lake Preview Version 8 is required. +* Ballerina SLAlpha2 Installed + Ballerina Swan Lake Alpha 2 is required. * Shared Access Signature (SAS) Authentication Credentials * Connection String @@ -113,8 +113,8 @@ First, import the ballerinax/asb module into the Ballerina project. You can now make the connection configuration using the connection string and entity path. ```ballerina asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; ``` @@ -205,8 +205,8 @@ First, import the ballerinax/asb module into the Ballerina project. You can now make the connection configuration using the connection string and entity path. ```ballerina asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; ``` @@ -250,8 +250,8 @@ the service logic to execute when a message is received inside the onMessage rem asb:Service asyncTestService = @asb:ServiceConfig { queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") + connectionString: , + queueName: } } service object { @@ -279,7 +279,7 @@ the connection with the Azure Service Bus. checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start listening"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end listening"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -326,8 +326,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -397,8 +397,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -469,8 +469,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -546,23 +546,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -652,1476 +652,5 @@ public function main() { } ``` -5. Send Batch to Topic and Receive from Subscription -This is the basic scenario of sending a batch of messages to a topic and receiving a batch of messages from -a subscription. A user must create a sender connection and a receiver connection with the azure service bus to send and -receive a message. The message body is passed as a parameter in byte array format with optional parameters and -properties to the send operation. The user can receive the array of Message objects at the other receiver end. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters3 = {contentType: "text/plain", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters3, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection 1."); - var messagesReceived = receiverConnection1->receiveBatchMessage(maxMessageCount); - if(messagesReceived is asb:Messages) { - int val = messagesReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messagesReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " + messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " + messageReceived2); - string messageReceived3 = checkpanic messages[2].getTextContent(); - log:print("Message3 content : " + messageReceived3); - }else { - log:printError("Receiving message via Asb receiver connection failed."); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection 2."); - var messagesReceived = receiverConnection2->receiveBatchMessage(maxMessageCount); - if(messagesReceived is asb:Messages) { - int val = messagesReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messagesReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " + messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " + messageReceived2); - string messageReceived3 = checkpanic messages[2].getTextContent(); - log:print("Message3 content : " + messageReceived3); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection 3."); - var messagesReceived = receiverConnection3->receiveBatchMessage(maxMessageCount); - if(messagesReceived is asb:Messages) { - int val = messagesReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messagesReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " + messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " + messageReceived2); - string messageReceived3 = checkpanic messages[2].getTextContent(); - log:print("Message3 content : " + messageReceived3); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -6. Complete Messages from Queue -This is the basic scenario of sending and completing messages from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can complete -all the Messages from the queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_messages_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "text/plain", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -7. Complete Message from Queue -This is the basic scenario of sending and completing a message from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can complete -single Messages from the queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_message_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "text/plain", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "sanju", replyTo: "carol", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection."); - checkpanic receiverConnection->completeOneMessage(); - checkpanic receiverConnection->completeOneMessage(); - checkpanic receiverConnection->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -8. Complete Messages from Subscription -This is the basic scenario of sending and completing messages from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -complete all the Messages from the subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_messages_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters = {contentType: "plain/text", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -9. Complete Message from Subscription -This is the basic scenario of sending and completing a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -complete single Messages from the subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_message_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters = {contentType: "application/text", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection 1."); - checkpanic receiverConnection1->completeOneMessage(); - checkpanic receiverConnection1->completeOneMessage(); - checkpanic receiverConnection1->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection 2."); - checkpanic receiverConnection2->completeOneMessage(); - checkpanic receiverConnection2->completeOneMessage(); - checkpanic receiverConnection2->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection 3."); - checkpanic receiverConnection3->completeOneMessage(); - checkpanic receiverConnection3->completeOneMessage(); - checkpanic receiverConnection3->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -10. Abandon Message from Queue -This is the basic scenario of sending and abandoning a message from a queue. A user must create a sender connection -and a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can abandon -a single Messages & make available again for processing from Queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/abandon_message_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "sanju", replyTo: "carol", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection."); - checkpanic receiverConnection->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -11. Abandon Message from Subscription -This is the basic scenario of sending and abandoning a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -abandon a single Messages & make available again for processing from subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/abandon_message_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters = {contentType: "application/text", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection 1."); - checkpanic receiverConnection1->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection 2."); - checkpanic receiverConnection2->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection 3."); - checkpanic receiverConnection3->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -12. Asynchronous Consumer -This is the basic scenario of sending and listening to messages from a queue. A user must create a sender connection -and a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can -asynchronously listen to messages from the azure service bus connection and execute the service logic based on the -message received. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/async_consumer.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerina/runtime; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - asb:Service asyncTestService = - @asb:ServiceConfig { - queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") - } - } - service object { - remote function onMessage(asb:Message message) { - var messageContent = message.getTextContent(); - if (messageContent is string) { - log:print("The message received: " + messageContent); - } else { - log:printError("Error occurred while retrieving the message content."); - } - } - }; - - asb:Listener? channelListener = new(); - if (channelListener is asb:Listener) { - checkpanic channelListener.attach(asyncTestService); - checkpanic channelListener.'start(); - log:print("start listening"); - runtime:sleep(20000); - log:print("end listening"); - checkpanic channelListener.detach(asyncTestService); - checkpanic channelListener.gracefulStop(); - checkpanic channelListener.immediateStop(); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } -} -``` - -13. Duplicate Messages Detection -This is the basic scenario of detecting duplicate messages from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can receive -the Message object at the other receiver end. If a duplicate message is received the receive operation fails. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/duplicate_messages_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - map parameters = {contentType: "plain/text", messageId: "one"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 2; - int serverWaitTime = 5; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection."); - var messageReceived = receiverConnection->receiveMessages(serverWaitTime, maxMessageCount); - if(messageReceived is asb:Messages) { - int val = messageReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messageReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " +messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " +messageReceived2.toString()); - } else { - log:printError(messageReceived.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -14. Deadletter from Queue -This is the basic scenario of sending and dead lettering a message from a queue. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -abandon a single Message & moves the message to the Dead-Letter Queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/deadletter_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection."); - checkpanic receiverConnection->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -15. Deadletter from Subscription -This is the basic scenario of sending and dead lettering a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -abandon a single Message & move the message to the Dead-Letter subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/deadletter_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection 1."); - checkpanic receiverConnection1->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection 2."); - checkpanic receiverConnection2->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection 3."); - checkpanic receiverConnection3->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -16. Defer from Queue -This is the basic scenario of sending and deferring a message from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can defer -a single Message. Deferred messages can only be received by using sequence number and return Message object. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/defer_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int serverWaitTime = 5; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection."); - var sequenceNumber = receiverConnection->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -17. Defer from Subscription -This is the basic scenario of sending and deferring a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -defer a single Message. Deferred messages can only be received by using sequence number and return Message object. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/defer_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int serverWaitTime = 5; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection 1."); - var sequenceNumber = receiverConnection1->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection 1."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection1->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection 1."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection1->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection 2."); - var sequenceNumber = receiverConnection2->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection 2."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection2->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection 2."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection2->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection 3."); - var sequenceNumber = receiverConnection3->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection 3."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection3->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection 3."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection3->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -18. Renew Lock on Message from Queue -This is the basic scenario of renewing a lock on a message from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can renew -a lock on a single Message from the queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/renew_lock_on_message_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection."); - checkpanic receiverConnection->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -19. Renew Lock on Message from Subscription -This is the basic scenario of renewing a lock on a message from a subscription. A user must create a sender connection -and a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can renew -a lock on a single Message from the subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection 1."); - checkpanic receiverConnection1->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection 2."); - checkpanic receiverConnection2->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection 3."); - checkpanic receiverConnection3->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` +More Samples are available at: +https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/tree/main/asb-ballerina/samples diff --git a/asb-ballerina/Package.md b/asb-ballerina/Package.md index 39d367f9..3d0d0095 100644 --- a/asb-ballerina/Package.md +++ b/asb-ballerina/Package.md @@ -13,7 +13,7 @@ basic operations. These APIs use SAS authentication and this module supports SAS # Compatibility | | Version | |:-------------------:|:---------------------------:| -| Ballerina Language | Swan-Lake-Preview8 | +| Ballerina Language | Swan-Lake-Alpha2 | | Service Bus API | v1.2.8 | # Supported Operations @@ -56,8 +56,8 @@ immediate stop listening. * Java 11 Installed Java Development Kit (JDK) with version 11 is required. -* Ballerina SLP8 Installed - Ballerina Swan Lake Preview Version 8 is required. +* Ballerina SLAlpha2 Installed + Ballerina Swan Lake Alpha 2 is required. * Shared Access Signature (SAS) Authentication Credentials * Connection String @@ -113,8 +113,8 @@ First, import the ballerinax/asb module into the Ballerina project. You can now make the connection configuration using the connection string and entity path. ```ballerina asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; ``` @@ -205,8 +205,8 @@ First, import the ballerinax/asb module into the Ballerina project. You can now make the connection configuration using the connection string and entity path. ```ballerina asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; ``` @@ -250,8 +250,8 @@ the service logic to execute when a message is received inside the onMessage rem asb:Service asyncTestService = @asb:ServiceConfig { queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") + connectionString: , + queueName: } } service object { @@ -279,7 +279,7 @@ the connection with the Azure Service Bus. checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start listening"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end listening"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -326,8 +326,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -397,8 +397,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -469,8 +469,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -546,23 +546,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -652,1476 +652,5 @@ public function main() { } ``` -5. Send Batch to Topic and Receive from Subscription -This is the basic scenario of sending a batch of messages to a topic and receiving a batch of messages from -a subscription. A user must create a sender connection and a receiver connection with the azure service bus to send and -receive a message. The message body is passed as a parameter in byte array format with optional parameters and -properties to the send operation. The user can receive the array of Message objects at the other receiver end. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters3 = {contentType: "text/plain", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters3, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection 1."); - var messagesReceived = receiverConnection1->receiveBatchMessage(maxMessageCount); - if(messagesReceived is asb:Messages) { - int val = messagesReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messagesReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " + messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " + messageReceived2); - string messageReceived3 = checkpanic messages[2].getTextContent(); - log:print("Message3 content : " + messageReceived3); - }else { - log:printError("Receiving message via Asb receiver connection failed."); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection 2."); - var messagesReceived = receiverConnection2->receiveBatchMessage(maxMessageCount); - if(messagesReceived is asb:Messages) { - int val = messagesReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messagesReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " + messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " + messageReceived2); - string messageReceived3 = checkpanic messages[2].getTextContent(); - log:print("Message3 content : " + messageReceived3); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection 3."); - var messagesReceived = receiverConnection3->receiveBatchMessage(maxMessageCount); - if(messagesReceived is asb:Messages) { - int val = messagesReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messagesReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " + messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " + messageReceived2); - string messageReceived3 = checkpanic messages[2].getTextContent(); - log:print("Message3 content : " + messageReceived3); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -6. Complete Messages from Queue -This is the basic scenario of sending and completing messages from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can complete -all the Messages from the queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_messages_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "text/plain", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -7. Complete Message from Queue -This is the basic scenario of sending and completing a message from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can complete -single Messages from the queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_message_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "text/plain", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "sanju", replyTo: "carol", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection."); - checkpanic receiverConnection->completeOneMessage(); - checkpanic receiverConnection->completeOneMessage(); - checkpanic receiverConnection->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -8. Complete Messages from Subscription -This is the basic scenario of sending and completing messages from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -complete all the Messages from the subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_messages_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters = {contentType: "plain/text", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -9. Complete Message from Subscription -This is the basic scenario of sending and completing a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -complete single Messages from the subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/complete_message_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters = {contentType: "application/text", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection 1."); - checkpanic receiverConnection1->completeOneMessage(); - checkpanic receiverConnection1->completeOneMessage(); - checkpanic receiverConnection1->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection 2."); - checkpanic receiverConnection2->completeOneMessage(); - checkpanic receiverConnection2->completeOneMessage(); - checkpanic receiverConnection2->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Completing message from Asb receiver connection 3."); - checkpanic receiverConnection3->completeOneMessage(); - checkpanic receiverConnection3->completeOneMessage(); - checkpanic receiverConnection3->completeOneMessage(); - log:print("Done completing a message using its lock token."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -10. Abandon Message from Queue -This is the basic scenario of sending and abandoning a message from a queue. A user must create a sender connection -and a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can abandon -a single Messages & make available again for processing from Queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/abandon_message_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "sanju", replyTo: "carol", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection."); - checkpanic receiverConnection->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -11. Abandon Message from Subscription -This is the basic scenario of sending and abandoning a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -abandon a single Messages & make available again for processing from subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/abandon_message_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string[] stringArrayContent = ["apple", "mango", "lemon", "orange"]; - map parameters = {contentType: "application/text", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 3; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendBatchMessage(stringArrayContent, parameters, properties, maxMessageCount); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection 1."); - checkpanic receiverConnection1->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection 2."); - checkpanic receiverConnection2->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("abandoning message from Asb receiver connection 3."); - checkpanic receiverConnection3->abandonMessage(); - log:print("Done abandoning a message using its lock token."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -12. Asynchronous Consumer -This is the basic scenario of sending and listening to messages from a queue. A user must create a sender connection -and a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can -asynchronously listen to messages from the azure service bus connection and execute the service logic based on the -message received. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/async_consumer.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerina/runtime; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - asb:Service asyncTestService = - @asb:ServiceConfig { - queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") - } - } - service object { - remote function onMessage(asb:Message message) { - var messageContent = message.getTextContent(); - if (messageContent is string) { - log:print("The message received: " + messageContent); - } else { - log:printError("Error occurred while retrieving the message content."); - } - } - }; - - asb:Listener? channelListener = new(); - if (channelListener is asb:Listener) { - checkpanic channelListener.attach(asyncTestService); - checkpanic channelListener.'start(); - log:print("start listening"); - runtime:sleep(20000); - log:print("end listening"); - checkpanic channelListener.detach(asyncTestService); - checkpanic channelListener.gracefulStop(); - checkpanic channelListener.immediateStop(); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } -} -``` - -13. Duplicate Messages Detection -This is the basic scenario of detecting duplicate messages from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can receive -the Message object at the other receiver end. If a duplicate message is received the receive operation fails. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/duplicate_messages_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - map parameters = {contentType: "plain/text", messageId: "one"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int maxMessageCount = 2; - int serverWaitTime = 5; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Receiving from Asb receiver connection."); - var messageReceived = receiverConnection->receiveMessages(serverWaitTime, maxMessageCount); - if(messageReceived is asb:Messages) { - int val = messageReceived.getMessageCount(); - log:print("No. of messages received : " + val.toString()); - asb:Message[] messages = messageReceived.getMessages(); - string messageReceived1 = checkpanic messages[0].getTextContent(); - log:print("Message1 content : " +messageReceived1); - string messageReceived2 = checkpanic messages[1].getTextContent(); - log:print("Message2 content : " +messageReceived2.toString()); - } else { - log:printError(messageReceived.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -14. Deadletter from Queue -This is the basic scenario of sending and dead lettering a message from a queue. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -abandon a single Message & moves the message to the Dead-Letter Queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/deadletter_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection."); - checkpanic receiverConnection->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -15. Deadletter from Subscription -This is the basic scenario of sending and dead lettering a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -abandon a single Message & move the message to the Dead-Letter subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/deadletter_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection 1."); - checkpanic receiverConnection1->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection 2."); - checkpanic receiverConnection2->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Dead-Letter message from Asb receiver connection 3."); - checkpanic receiverConnection3->deadLetterMessage("deadLetterReason", "deadLetterErrorDescription"); - log:print("Done Dead-Letter a message using its lock token."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -16. Defer from Queue -This is the basic scenario of sending and deferring a message from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can defer -a single Message. Deferred messages can only be received by using sequence number and return Message object. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/defer_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int serverWaitTime = 5; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection."); - var sequenceNumber = receiverConnection->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -17. Defer from Subscription -This is the basic scenario of sending and deferring a message from a subscription. A user must create a sender -connection and a receiver connection with the azure service bus to send and receive a message. The message body is -passed as a parameter in byte array format with optional parameters and properties to the send operation. The user can -defer a single Message. Deferred messages can only be received by using sequence number and return Message object. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/defer_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - int serverWaitTime = 5; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection 1."); - var sequenceNumber = receiverConnection1->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection 1."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection1->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection 1."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection1->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection 2."); - var sequenceNumber = receiverConnection2->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection 2."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection2->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection 2."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection2->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Defer message from Asb receiver connection 3."); - var sequenceNumber = receiverConnection3->deferMessage(); - log:print("Done Deferring a message using its lock token."); - log:print("Receiving from Asb receiver connection 3."); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection3->receiveMessage(serverWaitTime); - if (jsonMessageReceived is asb:Message) { - json jsonMessageRead = checkpanic jsonMessageReceived.getJSONContent(); - log:print("Reading Received Message : " + jsonMessageRead.toString()); - } else { - log:printError("Receiving message via Asb receiver connection failed."); - } - log:print("Receiving Deferred Message from Asb receiver connection 3."); - if(sequenceNumber is int) { - if(sequenceNumber == 0) { - log:printError("No message in the queue"); - } - asb:Message|asb:Error? messageReceived = receiverConnection3->receiveDeferredMessage(sequenceNumber); - if (messageReceived is asb:Message) { - string messageRead = checkpanic messageReceived.getTextContent(); - log:print("Reading Received Message : " + messageRead); - } else if (messageReceived is ()) { - log:printError("No deferred message received with given sequence number"); - } else { - log:printError(msg = messageReceived.message()); - } - } else { - log:printError(msg = sequenceNumber.message()); - } - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` - -18. Renew Lock on Message from Queue -This is the basic scenario of renewing a lock on a message from a queue. A user must create a sender connection and -a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can renew -a lock on a single Message from the queue. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/renew_lock_on_message_from_queue.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (config); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection = checkpanic new (config); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection."); - checkpanic receiverConnection->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection."); - checkpanic receiverConnection->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection."); - checkpanic receiverConnection.closeReceiverConnection(); - } -} -``` - -19. Renew Lock on Message from Subscription -This is the basic scenario of renewing a lock on a message from a subscription. A user must create a sender connection -and a receiver connection with the azure service bus to send and receive a message. The message body is passed as -a parameter in byte array format with optional parameters and properties to the send operation. The user can renew -a lock on a single Message from the subscription. - -Sample is available at: -https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/blob/main/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal - -```ballerina -import ballerina/config; -import ballerina/log; -import ballerinax/asb; - -public function main() { - - // Input values - string stringContent = "This is My Message Body"; - byte[] byteContent = stringContent.toBytes(); - json jsonContent = {name: "apple", color: "red", price: 5.36}; - byte[] byteContentFromJson = jsonContent.toJsonString().toBytes(); - map parameters1 = {contentType: "plain/text", messageId: "one"}; - map parameters2 = {contentType: "application/json", messageId: "two", to: "user1", replyTo: "user2", - label: "a1", sessionId: "b1", correlationId: "c1", timeToLive: "2"}; - map properties = {a: "propertyValue1", b: "propertyValue2"}; - - asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") - }; - - asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") - }; - - asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") - }; - - asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") - }; - - log:print("Creating Asb sender connection."); - asb:SenderConnection? senderConnection = checkpanic new (senderConfig); - - log:print("Creating Asb receiver connection."); - asb:ReceiverConnection? receiverConnection1 = checkpanic new (receiverConfig1); - asb:ReceiverConnection? receiverConnection2 = checkpanic new (receiverConfig2); - asb:ReceiverConnection? receiverConnection3 = checkpanic new (receiverConfig3); - - if (senderConnection is asb:SenderConnection) { - log:print("Sending via Asb sender connection."); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContent, parameters1, properties); - checkpanic senderConnection->sendMessageWithConfigurableParameters(byteContentFromJson, parameters2, properties); - } else { - log:printError("Asb sender connection creation failed."); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection 1."); - checkpanic receiverConnection1->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection 1."); - checkpanic receiverConnection1->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection 2."); - checkpanic receiverConnection2->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection 2."); - checkpanic receiverConnection2->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Renew lock on message from Asb receiver connection 3."); - checkpanic receiverConnection3->renewLockOnMessage(); - log:print("Done renewing a message."); - log:print("Completing messages from Asb receiver connection 3."); - checkpanic receiverConnection3->completeMessages(); - log:print("Done completing messages using their lock tokens."); - } else { - log:printError("Asb receiver connection creation failed."); - } - - if (senderConnection is asb:SenderConnection) { - log:print("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } - - if (receiverConnection1 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 1."); - checkpanic receiverConnection1.closeReceiverConnection(); - } - - if (receiverConnection2 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 2."); - checkpanic receiverConnection2.closeReceiverConnection(); - } - - if (receiverConnection3 is asb:ReceiverConnection) { - log:print("Closing Asb receiver connection 3."); - checkpanic receiverConnection3.closeReceiverConnection(); - } -} -``` +More Samples are available at: +https://github.com/ballerina-platform/module-ballerinax-azure-service-bus/tree/main/asb-ballerina/samples diff --git a/asb-ballerina/commons.bal b/asb-ballerina/commons.bal index 361e9dfa..83ffd73f 100644 --- a/asb-ballerina/commons.bal +++ b/asb-ballerina/commons.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -import ballerina/java; +import ballerina/jballerina.java as java; // Constants diff --git a/asb-ballerina/errors.bal b/asb-ballerina/errors.bal index 42ab24a9..c9cc8e02 100644 --- a/asb-ballerina/errors.bal +++ b/asb-ballerina/errors.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -28,9 +28,9 @@ public type Error AsbError; isolated function prepareError(string message, error? err = ()) returns Error { AsbError asbError; if (err is error) { - asbError = AsbError(message, err); + asbError = error AsbError(message, err); } else { - asbError = AsbError(message); + asbError = error AsbError(message); } return asbError; } diff --git a/asb-ballerina/listener.bal b/asb-ballerina/listener.bal index d62bc76d..8def142e 100644 --- a/asb-ballerina/listener.bal +++ b/asb-ballerina/listener.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -import ballerina/java; +import ballerina/jballerina.java as java; # Ballerina Asb Message Listener. # Provides a listener to consume messages from the Azure Service Bus. diff --git a/asb-ballerina/message.bal b/asb-ballerina/message.bal index 60117f6a..eef5113e 100644 --- a/asb-ballerina/message.bal +++ b/asb-ballerina/message.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -import ballerina/java; +import ballerina/jballerina.java as java; public class Message { private byte[] messageContent = []; diff --git a/asb-ballerina/messages.bal b/asb-ballerina/messages.bal index 17099b06..eddfdba9 100644 --- a/asb-ballerina/messages.bal +++ b/asb-ballerina/messages.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/asb-ballerina/receiver_connection.bal b/asb-ballerina/receiver_connection.bal index eaeb11f8..e4985adc 100644 --- a/asb-ballerina/receiver_connection.bal +++ b/asb-ballerina/receiver_connection.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -import ballerina/java; +import ballerina/jballerina.java as java; # Represents a single network receiver connection to the Asb broker. public client class ReceiverConnection { diff --git a/asb-ballerina/samples/.gitignore b/asb-ballerina/samples/.gitignore index 8674595a..5e074398 100644 --- a/asb-ballerina/samples/.gitignore +++ b/asb-ballerina/samples/.gitignore @@ -1 +1,2 @@ ballerina.conf +Config.toml diff --git a/asb-ballerina/samples/README.md b/asb-ballerina/samples/README.md index 229430e9..635cca38 100644 --- a/asb-ballerina/samples/README.md +++ b/asb-ballerina/samples/README.md @@ -28,8 +28,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -99,8 +99,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -171,8 +171,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -248,23 +248,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -377,23 +377,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -520,8 +520,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -588,8 +588,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -651,23 +651,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -763,23 +763,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -876,8 +876,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -940,23 +940,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1058,8 +1058,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1076,8 +1076,8 @@ public function main() { asb:Service asyncTestService = @asb:ServiceConfig { queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") + connectionString: , + queueName: } } service object { @@ -1096,7 +1096,7 @@ public function main() { checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start listening"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end listening"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -1135,8 +1135,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1210,8 +1210,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1278,23 +1278,23 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1396,8 +1396,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1487,23 +1487,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1670,8 +1670,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); @@ -1738,23 +1738,23 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: , + entityPath: }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: , + entityPath: }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/abandon_message_from_queue.bal b/asb-ballerina/samples/abandon_message_from_queue.bal index b55e981a..2a3dc502 100644 --- a/asb-ballerina/samples/abandon_message_from_queue.bal +++ b/asb-ballerina/samples/abandon_message_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -31,8 +34,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/abandon_message_from_subscription.bal b/asb-ballerina/samples/abandon_message_from_subscription.bal index 106f7125..e83ed508 100644 --- a/asb-ballerina/samples/abandon_message_from_subscription.bal +++ b/asb-ballerina/samples/abandon_message_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -27,23 +33,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/async_consumer.bal b/asb-ballerina/samples/async_consumer.bal index 1da0f88a..a2ce876a 100644 --- a/asb-ballerina/samples/async_consumer.bal +++ b/asb-ballerina/samples/async_consumer.bal @@ -14,11 +14,14 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; -import ballerina/runtime; +import ballerina/lang.runtime; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -32,8 +35,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -50,8 +53,8 @@ public function main() { asb:Service asyncTestService = @asb:ServiceConfig { queueConfig: { - connectionString: config:getAsString("CONNECTION_STRING"), - queueName: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + queueName: queuePath } } service object { @@ -70,7 +73,7 @@ public function main() { checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start listening"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end listening"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); diff --git a/asb-ballerina/samples/complete_message_from_queue.bal b/asb-ballerina/samples/complete_message_from_queue.bal index 341e2989..cc88c414 100644 --- a/asb-ballerina/samples/complete_message_from_queue.bal +++ b/asb-ballerina/samples/complete_message_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -31,8 +34,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/complete_message_from_subscription.bal b/asb-ballerina/samples/complete_message_from_subscription.bal index c7781171..6c86a187 100644 --- a/asb-ballerina/samples/complete_message_from_subscription.bal +++ b/asb-ballerina/samples/complete_message_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -27,23 +33,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/complete_messages_from_queue.bal b/asb-ballerina/samples/complete_messages_from_queue.bal index 71678546..dd5723ea 100644 --- a/asb-ballerina/samples/complete_messages_from_queue.bal +++ b/asb-ballerina/samples/complete_messages_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -31,8 +34,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/complete_messages_from_subscription.bal b/asb-ballerina/samples/complete_messages_from_subscription.bal index e9f595c8..02fd9ab1 100644 --- a/asb-ballerina/samples/complete_messages_from_subscription.bal +++ b/asb-ballerina/samples/complete_messages_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -27,23 +33,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/deadletter_from_queue.bal b/asb-ballerina/samples/deadletter_from_queue.bal index 41aa158b..3425ae7e 100644 --- a/asb-ballerina/samples/deadletter_from_queue.bal +++ b/asb-ballerina/samples/deadletter_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -31,8 +34,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/deadletter_from_subscription.bal b/asb-ballerina/samples/deadletter_from_subscription.bal index 1dce8853..00fea1c4 100644 --- a/asb-ballerina/samples/deadletter_from_subscription.bal +++ b/asb-ballerina/samples/deadletter_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -31,23 +37,23 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/defer_from_queue.bal b/asb-ballerina/samples/defer_from_queue.bal index f2e33af0..12f8bbdd 100644 --- a/asb-ballerina/samples/defer_from_queue.bal +++ b/asb-ballerina/samples/defer_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -32,8 +35,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/defer_from_subscription.bal b/asb-ballerina/samples/defer_from_subscription.bal index a6610fcc..ff3c5508 100644 --- a/asb-ballerina/samples/defer_from_subscription.bal +++ b/asb-ballerina/samples/defer_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -32,23 +38,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/duplicate_messages_from_queue.bal b/asb-ballerina/samples/duplicate_messages_from_queue.bal index 932288e5..2e83047b 100644 --- a/asb-ballerina/samples/duplicate_messages_from_queue.bal +++ b/asb-ballerina/samples/duplicate_messages_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -29,8 +32,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/renew_lock_on_message_from_queue.bal b/asb-ballerina/samples/renew_lock_on_message_from_queue.bal index 24d883ca..3f547de0 100644 --- a/asb-ballerina/samples/renew_lock_on_message_from_queue.bal +++ b/asb-ballerina/samples/renew_lock_on_message_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -31,8 +34,8 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal b/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal index c20ffdd5..faedaaa1 100644 --- a/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal +++ b/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -31,23 +37,23 @@ public function main() { map properties = {a: "propertyValue1", b: "propertyValue2"}; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/send_and_receive_batch_from_queue.bal b/asb-ballerina/samples/send_and_receive_batch_from_queue.bal index 5cecea8c..9bf09b58 100644 --- a/asb-ballerina/samples/send_and_receive_batch_from_queue.bal +++ b/asb-ballerina/samples/send_and_receive_batch_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -28,8 +31,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/send_and_receive_message_from_queue.bal b/asb-ballerina/samples/send_and_receive_message_from_queue.bal index 08d1d5dd..fb41bf23 100644 --- a/asb-ballerina/samples/send_and_receive_message_from_queue.bal +++ b/asb-ballerina/samples/send_and_receive_message_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -32,8 +35,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -52,8 +55,8 @@ public function main() { if (receiverConnection is asb:ReceiverConnection) { log:print("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = receiverConnection->receiveMessage(serverWaitTime); - asb:Message|asb:Error? jsonMessageReceived = receiverConnection->receiveMessage(serverWaitTime); + asb:Message|asb:Error? messageReceived = checkpanic receiverConnection->receiveMessage(serverWaitTime); + asb:Message|asb:Error? jsonMessageReceived = checkpanic receiverConnection->receiveMessage(serverWaitTime); if (messageReceived is asb:Message && jsonMessageReceived is asb:Message) { string messageRead = checkpanic messageReceived.getTextContent(); log:print("Reading Received Message : " + messageRead); diff --git a/asb-ballerina/samples/send_and_receive_message_from_queue_service.bal b/asb-ballerina/samples/send_and_receive_message_from_queue_service.bal index ef16fc1d..7901fccc 100644 --- a/asb-ballerina/samples/send_and_receive_message_from_queue_service.bal +++ b/asb-ballerina/samples/send_and_receive_message_from_queue_service.bal @@ -14,11 +14,14 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerina/http; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + service /asb on new http:Listener(9090) { resource function get sendAndReceive(http:Caller caller, http:Request req) @@ -37,9 +40,9 @@ service /asb on new http:Listener(9090) { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") - }; + connectionString: connectionString, + entityPath: queuePath + }; log:print("Creating Asb sender connection."); asb:SenderConnection? senderConnection = checkpanic new (config); diff --git a/asb-ballerina/samples/send_and_receive_messages_from_queue.bal b/asb-ballerina/samples/send_and_receive_messages_from_queue.bal index d7309ffe..6a1a360e 100644 --- a/asb-ballerina/samples/send_and_receive_messages_from_queue.bal +++ b/asb-ballerina/samples/send_and_receive_messages_from_queue.bal @@ -14,10 +14,13 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string queuePath = ?; + public function main() { // Input values @@ -33,8 +36,8 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: connectionString, + entityPath: queuePath }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal b/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal index d63c5037..cd3464b9 100644 --- a/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal +++ b/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -27,23 +33,23 @@ public function main() { int maxMessageCount = 3; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal b/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal index 9406900f..34813fa6 100644 --- a/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal +++ b/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal @@ -14,10 +14,16 @@ // specific language governing permissions and limitations // under the License. -import ballerina/config; import ballerina/log; import ballerinax/asb; +// Connection Configurations +configurable string connectionString = ?; +configurable string topicPath = ?; +configurable string subscriptionPath1 = ?; +configurable string subscriptionPath2 = ?; +configurable string subscriptionPath3 = ?; + public function main() { // Input values @@ -32,23 +38,23 @@ public function main() { int serverWaitTime = 5; asb:ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: connectionString, + entityPath: topicPath }; asb:ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: connectionString, + entityPath: subscriptionPath1 }; asb:ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: connectionString, + entityPath: subscriptionPath2 }; asb:ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: connectionString, + entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); diff --git a/asb-ballerina/sender_connection.bal b/asb-ballerina/sender_connection.bal index 0a7e4f30..44214183 100644 --- a/asb-ballerina/sender_connection.bal +++ b/asb-ballerina/sender_connection.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. // // WSO2 Inc. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -import ballerina/java; +import ballerina/jballerina.java as java; # Represents a single network sender connection to the Asb broker. public client class SenderConnection { diff --git a/asb-ballerina/tests/asb_test.bal b/asb-ballerina/tests/asb_test.bal index 13516d1b..4e10d2ff 100644 --- a/asb-ballerina/tests/asb_test.bal +++ b/asb-ballerina/tests/asb_test.bal @@ -16,18 +16,25 @@ import ballerina/test; import ballerina/log; -import ballerina/system; -import ballerina/config; -import ballerina/runtime; +import ballerina/os; +import ballerina/lang.runtime; import ballerina/time; -// Connection Configurations -string connectionString = config:getAsString("CONNECTION_STRING"); -string queuePath = getConfigValue("QUEUE_PATH"); -string topicPath = getConfigValue("TOPIC_PATH"); -string subscriptionPath1 = getConfigValue("SUBSCRIPTION_PATH1"); -string subscriptionPath2 = getConfigValue("SUBSCRIPTION_PATH2"); -string subscriptionPath3 = getConfigValue("SUBSCRIPTION_PATH3"); +// // Connection Configurations for Local Test +// configurable string connectionString = ?; +// configurable string queuePath = ?; +// configurable string topicPath = ?; +// configurable string subscriptionPath1 = ?; +// configurable string subscriptionPath2 = ?; +// configurable string subscriptionPath3 = ?; + +// Connection Configurations for Github Workflow +string connectionString = os:getEnv("CONNECTION_STRING"); +string queuePath = os:getEnv("QUEUE_PATH"); +string topicPath = os:getEnv("TOPIC_PATH"); +string subscriptionPath1 = os:getEnv("SUBSCRIPTION_PATH1"); +string subscriptionPath2 = os:getEnv("SUBSCRIPTION_PATH2"); +string subscriptionPath3 = os:getEnv("SUBSCRIPTION_PATH3"); SenderConnection? senderConnection = (); ReceiverConnection? receiverConnection = (); @@ -121,7 +128,7 @@ function testSendToQueueOperation() { # Test receive one message from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testReceiveFromQueueOperation() { @@ -152,7 +159,7 @@ function testReceiveFromQueueOperation() { # Test receive messages from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testReceiveMessagesFromQueueOperation() { @@ -206,7 +213,7 @@ function testSendBatchToQueueOperation() { # Test receive batch from queue operation @test:Config { - dependsOn: ["testSendBatchToQueueOperation"], + dependsOn: [testSendBatchToQueueOperation], enable: false } function testReceiveBatchFromQueueOperation() { @@ -241,7 +248,7 @@ function testReceiveBatchFromQueueOperation() { # Test complete Messages from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testCompleteMessagesFromQueueOperation() { @@ -267,7 +274,7 @@ function testCompleteMessagesFromQueueOperation() { # Test complete single messages from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testCompleteOneMessageFromQueueOperation() { @@ -292,7 +299,7 @@ function testCompleteOneMessageFromQueueOperation() { # Test abandon Message from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testAbandonMessageFromQueueOperation() { @@ -340,7 +347,7 @@ function testSendToTopicOperation() { # Test receive from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testReceiveFromSubscriptionOperation() { @@ -437,7 +444,7 @@ function testSendBatchToTopicOperation() { # Test receive batch from subscription operation @test:Config { - dependsOn: ["testSendBatchToTopicOperation"], + dependsOn: [testSendBatchToTopicOperation], enable: false } function testReceiveBatchFromSubscriptionOperation() { @@ -524,7 +531,7 @@ function testReceiveBatchFromSubscriptionOperation() { # Test complete Messages from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testCompleteMessagesFromSubscriptionOperation() { @@ -584,7 +591,7 @@ function testCompleteMessagesFromSubscriptionOperation() { # Test complete single messages from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testCompleteOneMessageFromSubscriptionOperation() { @@ -641,7 +648,7 @@ function testCompleteOneMessageFromSubscriptionOperation() { # Test abandon Message from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testAbandonMessageFromSubscriptionOperation() { @@ -721,7 +728,7 @@ service object{ # Test Listener capabilities @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } public function testAsyncConsumer() { @@ -737,7 +744,7 @@ public function testAsyncConsumer() { checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -770,7 +777,7 @@ function testSendDuplicateToQueueOperation() { # Test receive duplicate messages from queue operation @test:Config { - dependsOn: ["testSendDuplicateToQueueOperation"], + dependsOn: [testSendDuplicateToQueueOperation], enable: false } function testReceiveDuplicateMessagesFromQueueOperation() { @@ -804,7 +811,7 @@ function testReceiveDuplicateMessagesFromQueueOperation() { # Test Dead-Letter Message from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testDeadLetterFromQueueOperation() { @@ -830,7 +837,7 @@ function testDeadLetterFromQueueOperation() { # Test Dead-Letter Message from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testDeadLetterFromSubscriptionOperation() { @@ -890,7 +897,7 @@ function testDeadLetterFromSubscriptionOperation() { # Test Defer Message from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testDeferFromQueueOperation() { @@ -938,7 +945,7 @@ function testDeferFromQueueOperation() { # Test Defer Message from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testDeferFromSubscriptionOperation() { @@ -1064,7 +1071,7 @@ function testDeferFromSubscriptionOperation() { # Test Renew Lock on Message from queue operation @test:Config { - dependsOn: ["testSendToQueueOperation"], + dependsOn: [testSendToQueueOperation], enable: false } function testRenewLockOnMessageFromQueueOperation() { @@ -1090,7 +1097,7 @@ function testRenewLockOnMessageFromQueueOperation() { # Test Renew Lock on Message from subscription operation @test:Config { - dependsOn: ["testSendToTopicOperation"], + dependsOn: [testSendToTopicOperation], enable: false } function testRenewLockOnMessageFromSubscriptionOperation() { @@ -1346,7 +1353,7 @@ function testSendAndReceiveMessagesWithVariableLoadUsingWorkers() { if (senderConnection is SenderConnection) { int i = 1; while (i <= variableMessageCount) { - runtime:sleep(5000); + runtime:sleep(5); string stringContent = "This is My Message Body " + i.toString(); byte[] byteContent = stringContent.toBytes(); log:print("Sending message " + i.toString() + " via Asb sender connection."); @@ -1376,7 +1383,7 @@ function testSendAndReceiveMessagesWithVariableLoadUsingWorkers() { int startTimeMills = time1.time; int i = 1; while (i <= variableMessageCount) { - runtime:sleep(10000); + runtime:sleep(10); log:print("Receiving message " + i.toString() + " from Asb receiver connection."); Message|Error? messageReceived = receiverConnection->receiveMessage(serverWaitTime); if (messageReceived is Message && messageReceived.getMessageContentType() == "application/text") { @@ -1426,7 +1433,7 @@ function testListenerWithVariableLoadUsingWorkers() { if (senderConnection is SenderConnection) { int i = 1; while (i <= variableMessageCount) { - runtime:sleep(5000); + runtime:sleep(5); string stringContent = "This is My Message Body " + i.toString(); byte[] byteContent = stringContent.toBytes(); log:print("Sending message " + i.toString() + " via Asb sender connection."); @@ -1456,7 +1463,7 @@ function testListenerWithVariableLoadUsingWorkers() { checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start"); - runtime:sleep(30000); + runtime:sleep(30); log:print("end"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -1474,8 +1481,10 @@ function testListenerWithVariableLoadUsingWorkers() { } function testSendAndReceiveMessageFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -1521,12 +1530,15 @@ function testSendAndReceiveMessageFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testSendAndReceiveMessageFromQueueOperation], enable: true } function testSendAndReceiveMessagesFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -1574,12 +1586,15 @@ function testSendAndReceiveMessagesFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testSendAndReceiveMessagesFromQueueOperation], enable: true } function testSendAndReceiveBatchFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -1628,12 +1643,15 @@ function testSendAndReceiveBatchFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testSendAndReceiveBatchFromQueueOperation], enable: true } function testCompleteAllMessagesFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -1674,12 +1692,15 @@ function testCompleteAllMessagesFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testCompleteAllMessagesFromQueueOperation], enable: true } function testCompleteMessageFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -1719,12 +1740,15 @@ function testCompleteMessageFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testCompleteMessageFromQueueOperation], enable: true } function testAbandonMessagesFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -1765,27 +1789,36 @@ function testAbandonMessagesFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testAbandonMessagesFromQueueOperation], enable: true } function testSendToTopicAndReceiveFromSubscriptionOperation() { ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -1876,27 +1909,36 @@ function testSendToTopicAndReceiveFromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testSendToTopicAndReceiveFromSubscriptionOperation], enable: true } function testSendBatchToTopicAndReceiveFromSubscriptionOperation() { ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -1997,27 +2039,36 @@ function testSendBatchToTopicAndReceiveFromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testSendBatchToTopicAndReceiveFromSubscriptionOperation], enable: true } function testCompleteAllMessagesFromSubscriptionOperation() { ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -2091,27 +2142,36 @@ function testCompleteAllMessagesFromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testCompleteAllMessagesFromSubscriptionOperation], enable: true } function testCompleteMessageFromSubscriptionOperation() { - ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + ConnectionConfiguration senderConfig = { + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -2182,27 +2242,36 @@ function testCompleteMessageFromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testCompleteMessageFromSubscriptionOperation], enable: true } function testAbandonMessagesFromSubscriptionOperation() { - ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + ConnectionConfiguration senderConfig = { + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -2276,12 +2345,15 @@ function testAbandonMessagesFromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testAbandonMessagesFromSubscriptionOperation], enable: true } function testAsyncConsumerOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -2301,7 +2373,7 @@ function testAsyncConsumerOperation() { checkpanic channelListener.attach(asyncTestService); checkpanic channelListener.'start(); log:print("start"); - runtime:sleep(20000); + runtime:sleep(20); log:print("end"); checkpanic channelListener.detach(asyncTestService); checkpanic channelListener.gracefulStop(); @@ -2317,12 +2389,15 @@ function testAsyncConsumerOperation() { @test:Config { groups: ["asb"], + dependsOn: [testAsyncConsumerOperation], enable: true } function testDeadletterFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -2363,12 +2438,15 @@ function testDeadletterFromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testDeadletterFromQueueOperation], enable: true } function testDefer_FromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -2431,12 +2509,15 @@ function testDefer_FromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testDefer_FromQueueOperation], enable: true } function testRenewLockOnMessage_FromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -2477,27 +2558,36 @@ function testRenewLockOnMessage_FromQueueOperation() { @test:Config { groups: ["asb"], + dependsOn: [testRenewLockOnMessage_FromQueueOperation], enable: true } function testDeadletterFromSubscriptionOperation() { ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -2572,27 +2662,36 @@ function testDeadletterFromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testDeadletterFromSubscriptionOperation], enable: true } function testDefer_FromSubscriptionOperation() { ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -2733,27 +2832,36 @@ function testDefer_FromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testDefer_FromSubscriptionOperation], enable: true } function testRenewLockOnMessage_FromSubscriptionOperation() { ConnectionConfiguration senderConfig = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("TOPIC_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("TOPIC_PATH") + // connectionString: connectionString, + // entityPath: topicPath }; ConnectionConfiguration receiverConfig1 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH1") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH1") + // connectionString: connectionString, + // entityPath: subscriptionPath1 }; ConnectionConfiguration receiverConfig2 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH2") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH2") + // connectionString: connectionString, + // entityPath: subscriptionPath2 }; ConnectionConfiguration receiverConfig3 = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("SUBSCRIPTION_PATH3") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("SUBSCRIPTION_PATH3") + // connectionString: connectionString, + // entityPath: subscriptionPath3 }; log:print("Creating Asb sender connection."); @@ -2828,12 +2936,15 @@ function testRenewLockOnMessage_FromSubscriptionOperation() { @test:Config { groups: ["asb"], + dependsOn: [testRenewLockOnMessage_FromSubscriptionOperation], enable: true } function testDuplicateMessagesFromQueueOperation() { ConnectionConfiguration config = { - connectionString: config:getAsString("CONNECTION_STRING"), - entityPath: config:getAsString("QUEUE_PATH") + connectionString: os:getEnv("CONNECTION_STRING"), + entityPath: os:getEnv("QUEUE_PATH") + // connectionString: connectionString, + // entityPath: queuePath }; log:print("Creating Asb sender connection."); @@ -2896,9 +3007,9 @@ function afterSuiteFunc() { } } -# Get configuration value for the given key from ballerina.conf file. -# -# + return - configuration value of the given key as a string -isolated function getConfigValue(string key) returns string { - return (system:getEnv(key) != "") ? system:getEnv(key) : config:getAsString(key); -} +// # Get configuration value for the given key from ballerina.conf file. +// # +// # + return - configuration value of the given key as a string +// isolated function getConfigValue(string key) returns string { +// return (os:getEnv(key) != "") ? os:getEnv(key) : config:getAsString(key); +// } diff --git a/asb-native/assembly.xml b/asb-native/assembly.xml new file mode 100644 index 00000000..9682d731 --- /dev/null +++ b/asb-native/assembly.xml @@ -0,0 +1,28 @@ + + + + + + + org.ballerinalang:ballerina-runtime + org.ballerinalang:ballerina-lang + + + + diff --git a/asb-native/pom.xml b/asb-native/pom.xml index acb46cc5..7c91d873 100644 --- a/asb-native/pom.xml +++ b/asb-native/pom.xml @@ -1,6 +1,6 @@