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: