From aaf23c808066a6c1917c2480cbcea0a51d9c28d4 Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Wed, 5 May 2021 14:14:19 +0530 Subject: [PATCH 1/8] Add listener operations --- asb-ballerina/Ballerina.toml | 2 +- asb-ballerina/client.bal | 1 + asb-ballerina/listener.bal | 135 ++++++++++++++++++ asb-ballerina/tests/asb_test.bal | 58 ++++---- .../org/ballerinalang/asb/ASBConstants.java | 3 +- .../asb/connection/ListenerUtils.java | 29 +++- 6 files changed, 193 insertions(+), 35 deletions(-) diff --git a/asb-ballerina/Ballerina.toml b/asb-ballerina/Ballerina.toml index 2453d834..4dc24385 100644 --- a/asb-ballerina/Ballerina.toml +++ b/asb-ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "asb" -version = "0.1.2" +version = "0.1.3" license= ["Apache-2.0"] authors = ["Ballerina"] keywords = ["Azure","ServiceBus"] diff --git a/asb-ballerina/client.bal b/asb-ballerina/client.bal index bd864822..c1765d67 100644 --- a/asb-ballerina/client.bal +++ b/asb-ballerina/client.bal @@ -252,6 +252,7 @@ public client class AsbClient { # Defer the message in a Queue or Subscription based on messageLockToken. It prevents the message from being # directly received from the queue by setting it aside such that it must be received by sequence number. # + # + message - Message record # + return - An `asb:Error` if failed to defer message or else sequence number @display {label: "Defer Message"} isolated remote function defer(@display {label: "Message record"} Message message) diff --git a/asb-ballerina/listener.bal b/asb-ballerina/listener.bal index 48ac1b60..c790e9f8 100644 --- a/asb-ballerina/listener.bal +++ b/asb-ballerina/listener.bal @@ -65,6 +65,136 @@ public class Listener { public isolated function immediateStop() returns error? { return abortConnection(self); } + + # Complete message from queue or subscription based on messageLockToken. Declares the message processing to be + # successfully completed, removing the message from the queue. + # + # + message - Message record + # + return - An `asb:Error` if failed to complete message or else `()` + @display {label: "Complete Messages"} + public isolated function complete(@display {label: "Message record"} Message message) returns error? { + handle asbReceiverConnection = check getReceiver(self); + if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { + return complete(asbReceiverConnection, message?.lockToken.toString()); + } + return error Error("Failed to complete message with ID " + message?.messageId.toString()); + } + + # Abandon message from queue or subscription based on messageLockToken. Abandon processing of the message for + # the time being, returning the message immediately back to the queue to be picked up by another (or the same) + # receiver. + # + # + message - Message record + # + return - An `asb:Error` if failed to abandon message or else `()` + @display {label: "Abandon Message"} + public isolated function abandon(@display {label: "Message record"} Message message) returns Error? { + handle asbReceiverConnection = check getReceiver(self); + if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { + return abandon(asbReceiverConnection, message?.lockToken.toString()); + } + return error Error("Failed to abandon message with ID " + message?.messageId.toString()); + } + + # Dead-Letter the message & moves the message to the Dead-Letter Queue based on messageLockToken. Transfer + # the message from the primary queue into a special "dead-letter sub-queue". + # + # + message - Message record + # + deadLetterReason - The deadletter reason. + # + deadLetterErrorDescription - The deadletter error description. + # + return - An `asb:Error` if failed to deadletter message or else `()` + @display {label: "Dead Letter Message"} + public isolated function deadLetter(@display {label: "Message record"} Message message, + @display {label: "Dead letter reason (optional)"} string? deadLetterReason = (), + @display{label: "Dead letter description (optional)"} + string? deadLetterErrorDescription = ()) returns Error? { + handle asbReceiverConnection = check getReceiver(self); + if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { + return deadLetter(asbReceiverConnection, message?.lockToken.toString(), deadLetterReason, + deadLetterErrorDescription); + } + return error Error("Failed to deadletter message with ID " + message?.messageId.toString()); + } + + # Defer the message in a Queue or Subscription based on messageLockToken. It prevents the message from being + # directly received from the queue by setting it aside such that it must be received by sequence number. + # + # + message - Message record + # + return - An `asb:Error` if failed to defer message or else sequence number + @display {label: "Defer Message"} + public isolated function defer(@display {label: "Message record"} Message message) + returns @display {label: "Sequence Number of the deferred message"} int|Error { + handle asbReceiverConnection = check getReceiver(self); + _ = check defer(asbReceiverConnection, message?.lockToken.toString()); + return message?.sequenceNumber; + } + + # Receives a deferred Message. Deferred messages can only be received by using sequence number and return + # Message object. + # + # + sequenceNumber - Unique number assigned to a message by Service Bus. The sequence number is a unique 64-bit + # integer assigned to a message as it is accepted and stored by the broker and functions as + # its true identifier. + # + return - An `asb:Error` if failed to receive deferred message, a Message record if successful or else `()` + @display {label: "Receive Deferred Message"} + public isolated function receiveDeferred(@display {label: "Sequence Number of the deferred message"} + int sequenceNumber) + returns @display {label: "Deferred Message record"} Message|Error? { + handle asbReceiverConnection = check getReceiver(self); + Message|() message = check receiveDeferred(asbReceiverConnection, sequenceNumber); + if (message is Message) { + _ = check self.mapContentType(message); + return message; + } + return; + } + + # The operation renews lock on a message in a queue or subscription based on messageLockToken. + # + # + message - Message record + # + return - An `asb:Error` if failed to renew message or else `()` + @display {label: "Renew Lock on Message"} + public isolated function renewLock(@display {label: "Message record"} Message message) returns Error? { + handle asbReceiverConnection = check getReceiver(self); + if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { + return renewLock(asbReceiverConnection, message?.lockToken.toString()); + } + return error Error("Failed to renew lock on message with ID " + message?.messageId.toString()); + } + + # Set the prefetch count of the receiver. + # Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and + # before the application asks for one using Receive. Setting a non-zero value prefetches PrefetchCount + # number of messages. Setting the value to zero turns prefetch off. For both PEEKLOCK mode and + # RECEIVEANDDELETE mode, the default value is 0. + # + # + prefetchCount - The desired prefetch count. + # + return - An `asb:Error` if failed to renew message or else `()` + @display {label: "Set Prefetch Count"} + public isolated function setPrefetchCount(@display {label: "Prefetch count"} int prefetchCount) returns Error? { + handle asbReceiverConnection = check getReceiver(self); + return setPrefetchCount(asbReceiverConnection, prefetchCount); + } + + isolated function mapContentType(Message message) returns Error? { + match message?.contentType { + TEXT => { + message.body = check nativeGetTextContent( message.body); + } + JSON => { + message.body = check nativeGetJSONContent( message.body); + } + XML => { + message.body = check nativeGetXMLContent( message.body); + } + BYTE_ARRAY => { + message.body = message.body; + } + _ => { + message.body = message.body.toString(); + } + } + return; + } } # The ASB service type @@ -102,3 +232,8 @@ isolated function abortConnection(Listener lis) returns Error? = @java:Method { 'class: "org.ballerinalang.asb.connection.ListenerUtils" } external; + +isolated function getReceiver(Listener lis) returns handle|Error = +@java:Method { + 'class: "org.ballerinalang.asb.connection.ListenerUtils" +} external; diff --git a/asb-ballerina/tests/asb_test.bal b/asb-ballerina/tests/asb_test.bal index b25eed07..9cb58792 100644 --- a/asb-ballerina/tests/asb_test.bal +++ b/asb-ballerina/tests/asb_test.bal @@ -20,11 +20,11 @@ import ballerina/test; // Connection Configurations configurable string connectionString = os:getEnv("CONNECTION_STRING"); -configurable string queuePath = os:getEnv("QUEUE_PATH"); -configurable string topicPath = os:getEnv("TOPIC_PATH"); -configurable string subscriptionPath1 = os:getEnv("SUBSCRIPTION_PATH1"); -configurable string subscriptionPath2 = os:getEnv("SUBSCRIPTION_PATH2"); -configurable string subscriptionPath3 = os:getEnv("SUBSCRIPTION_PATH3"); +configurable string queueName = os:getEnv("QUEUE_NAME"); +configurable string topicName = os:getEnv("TOPIC_NAME"); +configurable string subscriptionName1 = os:getEnv("SUBSCRIPTION_NAME1"); +configurable string subscriptionName2 = os:getEnv("SUBSCRIPTION_NAME2"); +configurable string subscriptionName3 = os:getEnv("SUBSCRIPTION_NAME3"); // Input values string stringContent = "This is My Message Body"; @@ -70,10 +70,10 @@ function testSendAndReceiveMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, RECEIVEANDDELETE); + checkpanic asbClient->createQueueReceiver(queueName, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -107,10 +107,10 @@ function testSendAndReceiveBatchFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, RECEIVEANDDELETE); + checkpanic asbClient->createQueueReceiver(queueName, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->sendBatch(messages); @@ -148,10 +148,10 @@ function testCompleteMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, PEEKLOCK); + checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -185,10 +185,10 @@ function testAbandonMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, PEEKLOCK); + checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -230,10 +230,10 @@ function testDeadletterMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, PEEKLOCK); + checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -267,10 +267,10 @@ function testDeferMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, PEEKLOCK); + checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -310,10 +310,10 @@ function testSendAndReceiveMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, RECEIVEANDDELETE); + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -346,10 +346,10 @@ function testSendAndReceiveBatchFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, RECEIVEANDDELETE); + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->sendBatch(messages); @@ -386,10 +386,10 @@ function testCompleteMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, PEEKLOCK); + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -423,10 +423,10 @@ function testAbandonMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, PEEKLOCK); + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -466,10 +466,10 @@ function testDeadletterMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, PEEKLOCK); + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); @@ -503,10 +503,10 @@ function testDeferMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, PEEKLOCK); + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); checkpanic asbClient->send(message1); diff --git a/asb-native/src/main/java/org/ballerinalang/asb/ASBConstants.java b/asb-native/src/main/java/org/ballerinalang/asb/ASBConstants.java index 71a19ddf..a80d94b2 100644 --- a/asb-native/src/main/java/org/ballerinalang/asb/ASBConstants.java +++ b/asb-native/src/main/java/org/ballerinalang/asb/ASBConstants.java @@ -32,7 +32,7 @@ public class ASBConstants { // Asb package name constant fields public static final String ORG_NAME = "ballerinax"; public static final String ASB = "asb"; - public static final String ASB_VERSION = "0.1.2"; + public static final String ASB_VERSION = "0.1.3"; public static final Module PACKAGE_ID_ASB = new Module(ORG_NAME, ASB, ASB_VERSION); public static final String PACKAGE_ASB_FQN = ORG_NAME + ORG_NAME_SEPARATOR + ASB + VERSION_SEPARATOR + ASB_VERSION; @@ -84,6 +84,7 @@ public class ASBConstants { public static final BString QUEUE_NAME = StringUtils.fromString("entityPath"); public static final BString CONNECTION_STRING = StringUtils.fromString("connectionString"); + public static final BString RECEIVE_MODE = StringUtils.fromString("receiveMode"); public static final String CONNECTION_NATIVE_OBJECT = "asb_connection_object"; public static final String SERVICE_CONFIG = "ServiceConfig"; diff --git a/asb-native/src/main/java/org/ballerinalang/asb/connection/ListenerUtils.java b/asb-native/src/main/java/org/ballerinalang/asb/connection/ListenerUtils.java index 07ceac9e..f937be8f 100644 --- a/asb-native/src/main/java/org/ballerinalang/asb/connection/ListenerUtils.java +++ b/asb-native/src/main/java/org/ballerinalang/asb/connection/ListenerUtils.java @@ -31,8 +31,8 @@ import java.util.ArrayList; import java.util.logging.Logger; -import static org.ballerinalang.asb.MessageDispatcher.getConnectionStringFromConfig; -import static org.ballerinalang.asb.MessageDispatcher.getQueueNameFromConfig; +import static org.ballerinalang.asb.ASBConstants.RECEIVEANDDELETE; +import static org.ballerinalang.asb.MessageDispatcher.*; /** * Util class used to bridge the listener capabilities of the Asb connector's native code and the Ballerina API. @@ -69,8 +69,15 @@ public static Object registerListener(Environment environment, BObject listenerB try { String connectionString = getConnectionStringFromConfig(service); String entityPath = getQueueNameFromConfig(service); - IMessageReceiver receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder( - new ConnectionStringBuilder(connectionString, entityPath), ReceiveMode.PEEKLOCK); + String receiveMode = getReceiveModeFromConfig(service); + IMessageReceiver receiver; + if (receiveMode.equals(RECEIVEANDDELETE)) { + receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder( + new ConnectionStringBuilder(connectionString, entityPath), ReceiveMode.RECEIVEANDDELETE); + } else { + receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder( + new ConnectionStringBuilder(connectionString, entityPath), ReceiveMode.PEEKLOCK); + } listenerBObject.addNativeData(ASBConstants.CONNECTION_NATIVE_OBJECT, receiver); } catch (InterruptedException e) { throw ASBUtils.returnErrorValue("Current thread was interrupted while waiting " @@ -191,6 +198,20 @@ public static Object abortConnection(BObject listenerBObject) { return null; } + /** + * Get the receiver used by the listener. + * + * @param listenerBObject Ballerina listener object. + */ + public static Object getReceiver(BObject listenerBObject) { + IMessageReceiver iMessageReceiver = + (IMessageReceiver) listenerBObject.getNativeData(ASBConstants.CONNECTION_NATIVE_OBJECT); + if(iMessageReceiver == null) { + return ASBUtils.returnErrorValue("IMessageReceiver is not properly initialised."); + } + return iMessageReceiver; + } + /** * Starts consuming the messages by calling the message dispatcher. * From 5e12cba906b4eaf0fca76c19265171e2bf1c4561 Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Wed, 5 May 2021 14:14:49 +0530 Subject: [PATCH 2/8] Make receive mode configurable in listener --- asb-ballerina/commons.bal | 2 ++ .../ballerinalang/asb/MessageDispatcher.java | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/asb-ballerina/commons.bal b/asb-ballerina/commons.bal index 6053d028..7f50cee0 100644 --- a/asb-ballerina/commons.bal +++ b/asb-ballerina/commons.bal @@ -63,9 +63,11 @@ public type AsbConnectionConfiguration record {| # Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME; # SharedAccessSignatureToken=SHARED_ACCESS_SIGNATURE_TOKEN # + entityPath - Entitypath to the message broker resource +# + receiveMode - Message receive modes public type EntityConfiguration record {| string connectionString; string entityPath; + string receiveMode?; |}; # Service configurations used to create a `asb:Connection`. diff --git a/asb-native/src/main/java/org/ballerinalang/asb/MessageDispatcher.java b/asb-native/src/main/java/org/ballerinalang/asb/MessageDispatcher.java index 927758e1..2a212be7 100644 --- a/asb-native/src/main/java/org/ballerinalang/asb/MessageDispatcher.java +++ b/asb-native/src/main/java/org/ballerinalang/asb/MessageDispatcher.java @@ -108,6 +108,25 @@ public static String getConnectionStringFromConfig(BObject service) { return queueConfig.getStringValue(CONNECTION_STRING).getValue(); } + /** + * Get receive mode from annotation configuration attached to the service. + * + * @param service Ballerina service instance. + * @return Connection string from annotation configuration attached to the service. + */ + public static String getReceiveModeFromConfig(BObject service) { + BMap serviceConfig = (BMap) ((AnnotatableType) service.getType()) + .getAnnotation(StringUtils.fromString(ASBConstants.PACKAGE_ASB_FQN + ":" + + ASBConstants.SERVICE_CONFIG)); + @SuppressWarnings(ASBConstants.UNCHECKED) + BMap queueConfig = + (BMap) serviceConfig.getMapValue(ASBConstants.ALIAS_QUEUE_CONFIG); + if (queueConfig.getStringValue(RECEIVE_MODE) != null) { + return queueConfig.getStringValue(RECEIVE_MODE).getValue(); + } + return PEEKLOCK; + } + /** * Start receiving messages asynchronously and dispatch the messages to the attached service. * @@ -148,11 +167,11 @@ public void pumpMessage(IMessageReceiver receiver, ExecutorService executorServi pumpMessage(receiver, executorService); } else { handleDispatch(message); - try { - receiver.complete(message.getLockToken()); - } catch (Exception e) { - return ASBUtils.returnErrorValue(e.getMessage()); - } +// try { +// receiver.complete(message.getLockToken()); +// } catch (Exception e) { +// return ASBUtils.returnErrorValue(e.getMessage()); +// } pumpMessage(receiver, executorService); return null; } From d7b77c5a59fdda57e9780a6cd67fff420a5ff51f Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Wed, 5 May 2021 14:43:06 +0530 Subject: [PATCH 3/8] Update github workflow --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/pull-request.yml | 10 +++++----- .github/workflows/release.yml | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21a67392..15dff401 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,8 +72,8 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }} - QUEUE_PATH: ${{ secrets.QUEUE_PATH }} - TOPIC_PATH: ${{ secrets.TOPIC_PATH }} - SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_PATH1 }} - SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_PATH2 }} - SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_PATH3 }} + QUEUE_PATH: ${{ secrets.QUEUE_NAME }} + TOPIC_PATH: ${{ secrets.TOPIC_NAME }} + SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_NAME1 }} + SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_NAME2 }} + SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_NAME3 }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 36a341fb..8b4163a9 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -72,8 +72,8 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }} - QUEUE_PATH: ${{ secrets.QUEUE_PATH }} - TOPIC_PATH: ${{ secrets.TOPIC_PATH }} - SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_PATH1 }} - SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_PATH2 }} - SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_PATH3 }} + QUEUE_PATH: ${{ secrets.QUEUE_NAME }} + TOPIC_PATH: ${{ secrets.TOPIC_NAME }} + SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_NAME1 }} + SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_NAME2 }} + SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_NAME3 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b3fed901..f69e57ed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,11 +74,11 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }} - QUEUE_PATH: ${{ secrets.QUEUE_PATH }} - TOPIC_PATH: ${{ secrets.TOPIC_PATH }} - SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_PATH1 }} - SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_PATH2 }} - SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_PATH3 }} + QUEUE_PATH: ${{ secrets.QUEUE_NAME }} + TOPIC_PATH: ${{ secrets.TOPIC_NAME }} + SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_NAME1 }} + SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_NAME2 }} + SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_NAME3 }} # Push to Ballerina Central - name: Ballerina Push From bf3956bc16ec5d46aea005fda5ee0d51005daffd Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Wed, 5 May 2021 17:15:42 +0530 Subject: [PATCH 4/8] Upgrade ballerina lang version --- asb-native/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asb-native/pom.xml b/asb-native/pom.xml index f8016a2f..d8ab5330 100644 --- a/asb-native/pom.xml +++ b/asb-native/pom.xml @@ -81,13 +81,13 @@ org.ballerinalang ballerina-runtime - 2.0.0-alpha4 + 2.0.0-alpha7-20210403-234900-bdd55df1 provided org.ballerinalang ballerina-lang - 2.0.0-alpha4 + 2.0.0-alpha7-20210403-234900-bdd55df1 provided From f8957485a3975ed60de4fce9f13af84f6fc215b3 Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Thu, 6 May 2021 01:26:04 +0530 Subject: [PATCH 5/8] Revamp asb client --- asb-ballerina/Ballerina.toml | 2 +- asb-ballerina/client.bal | 126 ++++++++++++--------- asb-ballerina/tests/asb_test.bal | 183 ++++++++++++++++--------------- asb-native/pom.xml | 2 +- 4 files changed, 171 insertions(+), 142 deletions(-) diff --git a/asb-ballerina/Ballerina.toml b/asb-ballerina/Ballerina.toml index 4dc24385..aebcb20c 100644 --- a/asb-ballerina/Ballerina.toml +++ b/asb-ballerina/Ballerina.toml @@ -11,7 +11,7 @@ repository = "https://github.com/ballerina-platform/module-ballerinax-azure-serv observabilityIncluded = true [[platform.java11.dependency]] -path = "../asb-native/target/asb-native-1.0.1-jar-with-dependencies.jar" +path = "../asb-native/target/asb-native-1.0.2-jar-with-dependencies.jar" groupId = "org.ballerinalang" artifactId = "asb-native" module = "asb-native" diff --git a/asb-ballerina/client.bal b/asb-ballerina/client.bal index c1765d67..5f17047e 100644 --- a/asb-ballerina/client.bal +++ b/asb-ballerina/client.bal @@ -23,7 +23,6 @@ public client class AsbClient { handle asbReceiverConnection = JAVA_NULL; private string connectionString; - private string entityPath = ""; # Initiates an Asb Client using the given connection configuration. # @@ -35,15 +34,15 @@ public client class AsbClient { # Creates a queue sender connection to the given queue. # # + queueName - Name of the queue - # + return - An `asb:Error` if failed to create connection or else `()` + # + return - An `asb:Error` if failed to create connection or else `QueueSender` @display {label: "Create Queue Sender"} - isolated remote function createQueueSender(@display {label: "Queue name"} string queueName) returns Error? { - self.entityPath = queueName; + isolated remote function createQueueSender(@display {label: "Queue name"} string queueName) + returns @display {label: "QueueSender"} handle|Error { + string entityPath = queueName; var connectionResult = createSender(java:fromString(self.connectionString), - java:fromString(self.entityPath)); + java:fromString(entityPath)); if (connectionResult is handle) { - self.asbSenderConnection = connectionResult; - return; + return connectionResult; } else { return connectionResult; } @@ -52,15 +51,15 @@ public client class AsbClient { # Creates a topic sender connection to the given topic. # # + topicName - Name of the topic - # + return - An `asb:Error` if failed to create connection or else `()` + # + return - An `asb:Error` if failed to create connection or else `TopicSender` @display {label: "Create Topic Sender"} - isolated remote function createTopicSender(@display {label: "Topic name"} string topicName) returns Error? { - self.entityPath = topicName; + isolated remote function createTopicSender(@display {label: "Topic name"} string topicName) + returns @display {label: "TopicSender"} handle|Error { + string entityPath = topicName; var connectionResult = createSender(java:fromString(self.connectionString), - java:fromString(self.entityPath)); + java:fromString(entityPath)); if (connectionResult is handle) { - self.asbSenderConnection = connectionResult; - return; + return connectionResult; } else { return connectionResult; } @@ -70,18 +69,17 @@ public client class AsbClient { # # + queueName - Name of the queue # + receiveMode - Receive mode of the receiver. It can be PEEKLOCK or RECEIVEANDDELETE. Default is PEEKLOCK. - # + return - An `asb:Error` if failed to create connection or else `()` + # + return - An `asb:Error` if failed to create connection or else `QueueReceiver` @display {label: "Create Queue Receiver"} isolated remote function createQueueReceiver(@display {label: "Queue name"} string queueName, @display {label: "Receive mode (optional)"} string? receiveMode = PEEKLOCK) - returns Error? { - self.entityPath = queueName; + returns @display {label: "QueueReceiver"} handle|Error { + string entityPath = queueName; var connectionResult = createReceiver(java:fromString(self.connectionString), - java:fromString(self.entityPath), receiveMode); + java:fromString(entityPath), receiveMode); if (connectionResult is handle) { - self.asbReceiverConnection = connectionResult; - return; + return connectionResult; } else { return connectionResult; } @@ -92,18 +90,18 @@ public client class AsbClient { # + topicName - Name of the topic # + subscriptionName - Name of the subscription # + receiveMode - Receive mode of the receiver. It can be PEEKLOCK or RECEIVEANDDELETE. Default is PEEKLOCK. - # + return - An `asb:Error` if failed to create connection or else `()` + # + return - An `asb:Error` if failed to create connection or else `SubscriptionReceiver` @display {label: "Create Subscription Receiver"} isolated remote function createSubscriptionReceiver(@display {label: "Topic name"} string topicName, @display {label: "Subscription name"} string subscriptionName, @display {label: "Receive mode (optional)"} - string? receiveMode = PEEKLOCK) returns Error? { - self.entityPath = topicName + "/subscriptions/" + subscriptionName; + string? receiveMode = PEEKLOCK) + returns @display {label: "SubscriptionReceiver"} handle|Error { + string entityPath = topicName + "/subscriptions/" + subscriptionName; var connectionResult = createReceiver(java:fromString(self.connectionString), - java:fromString(self.entityPath), receiveMode); + java:fromString(entityPath), receiveMode); if (connectionResult is handle) { - self.asbReceiverConnection = connectionResult; - return; + return connectionResult; } else { return connectionResult; } @@ -111,10 +109,11 @@ public client class AsbClient { # Closes the Asb sender connection. # + # + asbSender - Asb Sender # + return - An `asb:Error` if failed to close connection or else `()` @display {label: "Close Sender Connection"} - isolated remote function closeSender() returns Error? { - var connectionResult = closeSender(self.asbSenderConnection); + isolated remote function closeSender(@display {label: "Asb Sender"} handle asbSender) returns Error? { + var connectionResult = closeSender(asbSender); if (connectionResult is ()) { return; } else { @@ -124,10 +123,11 @@ public client class AsbClient { # Closes the Asb receiver connection. # + # + asbReceiver - Asb Receiver # + return - An `asb:Error` if failed to close connection or else `()` @display {label: "Close Receiver Client Connection"} - isolated remote function closeReceiver() returns Error? { - var connectionResult = closeReceiver(self.asbReceiverConnection); + isolated remote function closeReceiver(@display {label: "Asb Receiver"} handle asbReceiver) returns Error? { + var connectionResult = closeReceiver(asbReceiver); if (connectionResult is ()) { return; } else { @@ -137,18 +137,20 @@ public client class AsbClient { # Send message to queue or topic with a message body # + # + asbSender - Asb Sender # + message - Azure service bus message representation # + return - An `asb:Error` if failed to send message or else `()` @display {label: "Send Message"} - isolated remote function send(@display {label: "Message record"} Message message) returns Error? { + isolated remote function send(@display {label: "Asb Sender"} handle asbSender, + @display {label: "Message record"} Message message) returns Error? { if (message.body is byte[]) { - return send(self.asbSenderConnection, message.body, message?.contentType, + return send(asbSender, message.body, message?.contentType, message?.messageId, message?.to, message?.replyTo, message?.replyToSessionId, message?.label, message?.sessionId, message?.correlationId, message?.partitionKey, message?.timeToLive, message?.applicationProperties?.properties); } else { byte[] messageBodyAsByteArray = message.body.toString().toBytes(); - return send(self.asbSenderConnection, messageBodyAsByteArray, message?.contentType, + return send(asbSender, messageBodyAsByteArray, message?.contentType, message?.messageId, message?.to, message?.replyTo, message?.replyToSessionId, message?.label, message?.sessionId, message?.correlationId, message?.partitionKey, message?.timeToLive, message?.applicationProperties?.properties); @@ -157,22 +159,26 @@ public client class AsbClient { # Send batch of messages to queue or topic # + # + asbSender - Asb Sender # + messages - Azure service bus batch message representation # + return - An `asb:Error` if failed to send message or else `()` @display {label: "Send Batch Message"} - isolated remote function sendBatch(@display {label: "Message Batch record"} MessageBatch messages) returns Error? { + isolated remote function sendBatch(@display {label: "Asb Sender"} handle asbSender, + @display {label: "Message Batch record"} MessageBatch messages) returns Error? { self.modifyContentToByteArray(messages); - return sendBatch(self.asbSenderConnection, messages); + return sendBatch(asbSender, messages); } # Receive message from queue or subscription. # + # + asbReceiver - Asb Receiver # + serverWaitTime - Specified server wait time in seconds to receive message. # + return - A Message record. An `asb:Error` if failed to receive message or else `()`. @display {label: "Receive Message"} - isolated remote function receive(@display {label: "Server wait time in seconds to receive message (optional)"} + isolated remote function receive(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Server wait time in seconds to receive message (optional)"} int? serverWaitTime) returns @display {label: "Message"} Message|Error? { - Message|() message = check receive(self.asbReceiverConnection, serverWaitTime); + Message|() message = check receive(asbReceiver, serverWaitTime); if (message is Message) { _ = check self.mapContentType(message); return message; @@ -182,15 +188,17 @@ public client class AsbClient { # Receive batch of messages from queue or subscription. # + # + asbReceiver - Asb Receiver # + maxMessageCount - Maximum message count to receive in a batch # + serverWaitTime - Specified server wait time in seconds to receive message. # + return - A Messages record. An `asb:Error` if failed to receive message or else `()`. @display {label: "Receive Batch Message"} - isolated remote function receiveBatch(@display {label: "Maximum number of messages in a batch"} int maxMessageCount, + isolated remote function receiveBatch(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Maximum number of messages in a batch"} int maxMessageCount, @display {label: "Server wait time in seconds to receive message (optional)"} int? serverWaitTime = ()) returns @display {label: "Batch Message"} MessageBatch|Error? { - MessageBatch|() receivedMessages = check receiveBatch(self.asbReceiverConnection, maxMessageCount, + MessageBatch|() receivedMessages = check receiveBatch(asbReceiver, maxMessageCount, serverWaitTime); if (receivedMessages is MessageBatch) { foreach Message message in receivedMessages.messages { @@ -206,12 +214,14 @@ public client class AsbClient { # Complete message from queue or subscription based on messageLockToken. Declares the message processing to be # successfully completed, removing the message from the queue. # + # + asbReceiver - Asb Receiver # + message - Message record # + return - An `asb:Error` if failed to complete message or else `()` @display {label: "Complete Messages"} - isolated remote function complete(@display {label: "Message record"} Message message) returns Error? { + isolated remote function complete(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Message record"} Message message) returns Error? { if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { - return complete(self.asbReceiverConnection, message?.lockToken.toString()); + return complete(asbReceiver, message?.lockToken.toString()); } return error Error("Failed to complete message with ID " + message?.messageId.toString()); } @@ -220,12 +230,14 @@ public client class AsbClient { # the time being, returning the message immediately back to the queue to be picked up by another (or the same) # receiver. # + # + asbReceiver - Asb Receiver # + message - Message record # + return - An `asb:Error` if failed to abandon message or else `()` @display {label: "Abandon Message"} - isolated remote function abandon(@display {label: "Message record"} Message message) returns Error? { + isolated remote function abandon(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Message record"} Message message) returns Error? { if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { - return abandon(self.asbReceiverConnection, message?.lockToken.toString()); + return abandon(asbReceiver, message?.lockToken.toString()); } return error Error("Failed to abandon message with ID " + message?.messageId.toString()); } @@ -233,17 +245,19 @@ public client class AsbClient { # Dead-Letter the message & moves the message to the Dead-Letter Queue based on messageLockToken. Transfer # the message from the primary queue into a special "dead-letter sub-queue". # + # + asbReceiver - Asb Receiver # + message - Message record # + deadLetterReason - The deadletter reason. # + deadLetterErrorDescription - The deadletter error description. # + return - An `asb:Error` if failed to deadletter message or else `()` @display {label: "Dead Letter Message"} - isolated remote function deadLetter(@display {label: "Message record"} Message message, + isolated remote function deadLetter(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Message record"} Message message, @display {label: "Dead letter reason (optional)"} string? deadLetterReason = (), @display{label: "Dead letter description (optional)"} string? deadLetterErrorDescription = ()) returns Error? { if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { - return deadLetter(self.asbReceiverConnection, message?.lockToken.toString(), deadLetterReason, + return deadLetter(asbReceiver, message?.lockToken.toString(), deadLetterReason, deadLetterErrorDescription); } return error Error("Failed to deadletter message with ID " + message?.messageId.toString()); @@ -252,27 +266,31 @@ public client class AsbClient { # Defer the message in a Queue or Subscription based on messageLockToken. It prevents the message from being # directly received from the queue by setting it aside such that it must be received by sequence number. # + # + asbReceiver - Asb Receiver # + message - Message record # + return - An `asb:Error` if failed to defer message or else sequence number @display {label: "Defer Message"} - isolated remote function defer(@display {label: "Message record"} Message message) + isolated remote function defer(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Message record"} Message message) returns @display {label: "Sequence Number of the deferred message"} int|Error { - _ = check defer(self.asbReceiverConnection, message?.lockToken.toString()); + _ = check defer(asbReceiver, message?.lockToken.toString()); return message?.sequenceNumber; } # Receives a deferred Message. Deferred messages can only be received by using sequence number and return # Message object. # + # + asbReceiver - Asb Receiver # + sequenceNumber - Unique number assigned to a message by Service Bus. The sequence number is a unique 64-bit # integer assigned to a message as it is accepted and stored by the broker and functions as # its true identifier. # + return - An `asb:Error` if failed to receive deferred message, a Message record if successful or else `()` @display {label: "Receive Deferred Message"} - isolated remote function receiveDeferred(@display {label: "Sequence Number of the deferred message"} + isolated remote function receiveDeferred(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Sequence Number of the deferred message"} int sequenceNumber) returns @display {label: "Deferred Message record"} Message|Error? { - Message|() message = check receiveDeferred(self.asbReceiverConnection, sequenceNumber); + Message|() message = check receiveDeferred(asbReceiver, sequenceNumber); if (message is Message) { _ = check self.mapContentType(message); return message; @@ -282,11 +300,13 @@ public client class AsbClient { # The operation renews lock on a message in a queue or subscription based on messageLockToken. # + # + asbReceiver - Asb Receiver # + return - An `asb:Error` if failed to renew message or else `()` @display {label: "Renew Lock on Message"} - isolated remote function renewLock(@display {label: "Message record"} Message message) returns Error? { + isolated remote function renewLock(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Message record"} Message message) returns Error? { if (message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN) { - return renewLock(self.asbReceiverConnection, message?.lockToken.toString()); + return renewLock(asbReceiver, message?.lockToken.toString()); } return error Error("Failed to renew lock on message with ID " + message?.messageId.toString()); } @@ -297,11 +317,13 @@ public client class AsbClient { # number of messages. Setting the value to zero turns prefetch off. For both PEEKLOCK mode and # RECEIVEANDDELETE mode, the default value is 0. # + # + asbReceiver - Asb Receiver # + prefetchCount - The desired prefetch count. # + return - An `asb:Error` if failed to renew message or else `()` @display {label: "Set Prefetch Count"} - isolated remote function setPrefetchCount(@display {label: "Prefetch count"} int prefetchCount) returns Error? { - return setPrefetchCount(self.asbReceiverConnection, prefetchCount); + isolated remote function setPrefetchCount(@display {label: "Asb Receiver"} handle asbReceiver, + @display {label: "Prefetch count"} int prefetchCount) returns Error? { + return setPrefetchCount(asbReceiver, prefetchCount); } isolated function mapContentType(Message message) returns Error? { diff --git a/asb-ballerina/tests/asb_test.bal b/asb-ballerina/tests/asb_test.bal index 9cb58792..78f225da 100644 --- a/asb-ballerina/tests/asb_test.bal +++ b/asb-ballerina/tests/asb_test.bal @@ -70,16 +70,16 @@ function testSendAndReceiveMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queueName, RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is Message) { log:printInfo(messageReceived.toString()); @@ -91,10 +91,10 @@ function testSendAndReceiveMessageFromQueueOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } @test:Config { @@ -107,16 +107,16 @@ function testSendAndReceiveBatchFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queueName, RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(queueSender, messages); log:printInfo("Receiving from Asb receiver connection."); - MessageBatch|Error? messageReceived = asbClient->receiveBatch(maxMessageCount); + MessageBatch|Error? messageReceived = asbClient->receiveBatch(queueReceiver, maxMessageCount); if (messageReceived is MessageBatch) { log:printInfo(messageReceived.toString()); @@ -132,10 +132,10 @@ function testSendAndReceiveBatchFromQueueOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } @test:Config { @@ -148,19 +148,19 @@ function testCompleteMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is Message) { - var result = checkpanic asbClient->complete(messageReceived); + var result = checkpanic asbClient->complete(queueReceiver, messageReceived); test:assertEquals(result, (), msg = "Complete message not succesful."); } else if (messageReceived is ()) { test:assertFail("No message in the queue."); @@ -169,10 +169,10 @@ function testCompleteMessageFromQueueOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } @test:Config { @@ -185,25 +185,25 @@ function testAbandonMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is Message) { - var result = checkpanic asbClient->abandon(messageReceived); + var result = checkpanic asbClient->abandon(queueReceiver, messageReceived); test:assertEquals(result, (), msg = "Abandon message not succesful."); - Message|Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + Message|Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is Message) { test:assertEquals(messageReceivedAgain?.messageId, messageReceived?.messageId, msg = "Abandon message not succesful."); - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(queueReceiver, messageReceivedAgain); } else { test:assertFail("Abandon message not succesful."); } @@ -214,10 +214,10 @@ function testAbandonMessageFromQueueOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } @test:Config { @@ -230,19 +230,19 @@ function testDeadletterMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is Message) { - var result = checkpanic asbClient->deadLetter(messageReceived); + var result = checkpanic asbClient->deadLetter(queueReceiver, messageReceived); test:assertEquals(result, (), msg = "Deadletter message not succesful."); } else if (messageReceived is ()) { test:assertFail("No message in the queue."); @@ -251,10 +251,10 @@ function testDeadletterMessageFromQueueOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } @test:Config { @@ -267,25 +267,25 @@ function testDeferMessageFromQueueOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is Message) { - int result = checkpanic asbClient->defer(messageReceived); + int result = checkpanic asbClient->defer(queueReceiver, messageReceived); test:assertNotEquals(result, 0, msg = "Defer message not succesful."); - Message|Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(result); + Message|Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(queueReceiver, result); if (messageReceivedAgain is Message) { test:assertEquals(messageReceivedAgain?.messageId, messageReceived?.messageId, msg = "Receiving deferred message not succesful."); - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(queueReceiver, messageReceivedAgain); } } else if (messageReceived is ()) { test:assertFail("No message in the queue."); @@ -294,10 +294,10 @@ function testDeferMessageFromQueueOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } @test:Config { @@ -310,16 +310,17 @@ function testSendAndReceiveMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicName); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is Message) { test:assertEquals(messageReceived.body, stringContent, msg = "Sent & recieved message not equal."); @@ -330,10 +331,10 @@ function testSendAndReceiveMessageFromSubscriptionOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } @test:Config { @@ -346,16 +347,18 @@ function testSendAndReceiveBatchFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicName); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(topicSender, messages); log:printInfo("Receiving from Asb receiver connection."); - MessageBatch|Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + MessageBatch|Error? messageReceived = + asbClient->receiveBatch(subscriptionReceiver, maxMessageCount, serverWaitTime); if (messageReceived is MessageBatch) { foreach Message message in messageReceived.messages { @@ -370,10 +373,10 @@ function testSendAndReceiveBatchFromSubscriptionOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } @test:Config { @@ -386,19 +389,20 @@ function testCompleteMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicName); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is Message) { - var result = checkpanic asbClient->complete(messageReceived); + var result = checkpanic asbClient->complete(subscriptionReceiver, messageReceived); test:assertEquals(result, (), msg = "Complete message not succesful."); } else if (messageReceived is ()) { test:assertFail("No message in the subscription."); @@ -407,10 +411,10 @@ function testCompleteMessageFromSubscriptionOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } @test:Config { @@ -423,23 +427,24 @@ function testAbandonMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicName); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is Message) { - var result = checkpanic asbClient->abandon(messageReceived); + var result = checkpanic asbClient->abandon(subscriptionReceiver, messageReceived); test:assertEquals(result, (), msg = "Abandon message not succesful."); - Message|Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + Message|Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(subscriptionReceiver, messageReceivedAgain); } else { test:assertFail("Abandon message not succesful."); } @@ -450,10 +455,10 @@ function testAbandonMessageFromSubscriptionOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } @test:Config { @@ -466,19 +471,20 @@ function testDeadletterMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicName); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is Message) { - var result = checkpanic asbClient->deadLetter(messageReceived); + var result = checkpanic asbClient->deadLetter(subscriptionReceiver, messageReceived); test:assertEquals(result, (), msg = "Deadletter message not succesful."); } else if (messageReceived is ()) { test:assertFail("No message in the subscription."); @@ -487,10 +493,10 @@ function testDeadletterMessageFromSubscriptionOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } @test:Config { @@ -503,25 +509,26 @@ function testDeferMessageFromSubscriptionOperation() { AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicName); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - Message|Error? messageReceived = asbClient->receive(serverWaitTime); + Message|Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is Message) { - int result = checkpanic asbClient->defer(messageReceived); + int result = checkpanic asbClient->defer(subscriptionReceiver, messageReceived); test:assertNotEquals(result, 0, msg = "Defer message not succesful."); - Message|Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(result); + Message|Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(subscriptionReceiver, result); if (messageReceivedAgain is Message) { test:assertEquals(messageReceivedAgain?.messageId, messageReceived?.messageId, msg = "Receiving deferred message not succesful."); - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(subscriptionReceiver, messageReceivedAgain); } } else if (messageReceived is ()) { test:assertFail("No message in the queue."); @@ -530,8 +537,8 @@ function testDeferMessageFromSubscriptionOperation() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-native/pom.xml b/asb-native/pom.xml index d8ab5330..dc8730f5 100644 --- a/asb-native/pom.xml +++ b/asb-native/pom.xml @@ -23,7 +23,7 @@ org.ballerinalang asb-native - 1.0.1 + 1.0.2 jar From 3feabb60249b7a200647f590de1d708755e6b58b Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Thu, 6 May 2021 01:26:42 +0530 Subject: [PATCH 6/8] Update samples and documentation --- README.md | 314 +++++++++--------- asb-ballerina/Module.md | 59 ++-- asb-ballerina/Package.md | 59 ++-- asb-ballerina/samples/README.md | 286 ++++++++-------- .../samples/abandon_message_from_queue.bal | 20 +- .../abandon_message_from_subscription.bal | 23 +- asb-ballerina/samples/async_consumer.bal | 10 +- .../samples/complete_message_from_queue.bal | 16 +- .../complete_message_from_subscription.bal | 19 +- .../samples/deadletter_from_queue.bal | 18 +- .../samples/deadletter_from_subscription.bal | 21 +- asb-ballerina/samples/defer_from_queue.bal | 19 +- .../samples/defer_from_subscription.bal | 22 +- .../renew_lock_on_message_from_queue.bal | 23 +- ...enew_lock_on_message_from_subscription.bal | 27 +- .../send_and_receive_batch_from_queue.bal | 15 +- .../send_and_receive_message_from_queue.bal | 14 +- ...to_topic_and_receive_from_subscription.bal | 18 +- ...to_topic_and_receive_from_subscription.bal | 17 +- 19 files changed, 502 insertions(+), 498 deletions(-) diff --git a/README.md b/README.md index 371b3363..af1179ee 100644 --- a/README.md +++ b/README.md @@ -179,14 +179,14 @@ You can now make an Azure service bus client using the connection configuration. ### Step 4: Create a Queue Sender using the Azure service bus client You can now make a sender connection using the Azure service bus client. Provide the `queueName` as a parameter. ```ballerina - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); ``` ### Step 5 : Create a Queue Receiver using the Azure service bus client You can now make a receiver connection using the connection configuration. Provide the `queueName` as a parameter. Optionally you can provide the receive mode which is PEEKLOCK by default. ```ballerina - checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); ``` ### Step 6: Initialize the Input Values @@ -215,13 +215,13 @@ Initialize the message to be sent with message body, optional parameters and pro You can now send a message to the configured azure service bus entity with message body, optional parameters and properties. Here we have shown how to send a text message parsed to the byte array format. ```ballerina - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); ``` ### Step 8: Receive a Message from Azure Service Bus You can now receive a message from the configured azure service bus entity. ```ballerina - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -235,13 +235,13 @@ You can now receive a message from the configured azure service bus entity. ### Step 9: Close Sender Connection You can now close the sender connection. ```ballerina - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); ``` ### Step 10: Close Receiver Connection You can now close the receiver connection. ```ballerina - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); ``` ## Send and Listen to Messages from the Azure Service Bus Queue @@ -289,7 +289,7 @@ You can now make an Azure service bus client using the connection configuration. ### Step 4: Create a Queue Sender using the Azure service bus client You can now make a sender connection using the Azure service bus client. Provide the `queueName` as a parameter. ```ballerina - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); ``` ### Step 5: Initialize the Input Values @@ -318,19 +318,19 @@ Initialize the message to be sent with message body, optional parameters and pro You can now send a message to the configured azure service bus entity with message body, optional parameters and properties. Here we have shown how to send a text message parsed to the byte array format. ```ballerina - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); ``` ### Step 7: Create a service object with the service configuration and the service logic to execute based on the message received You can now create a service object with the service configuration specified using the @asb:ServiceConfig annotation. -We need to give the connection string and the entity path of the queue we are to listen messages from. Then we can give -the service logic to execute when a message is received inside the onMessage remote function. +We need to give the connection string and the entity path of the queue we are to listen messages from. We can optionally provide the receive mode. Default mode is the PEEKLOCK mode. Then we can give the service logic to execute when a message is received inside the onMessage remote function. ```ballerina asb:Service asyncTestService = @asb:ServiceConfig { entityConfig: { connectionString: , - entityPath: + entityPath: , + receiveMode: } } service object { @@ -365,13 +365,9 @@ the connection with the Azure Service Bus. ### Step 9: Close Sender Connection You can now close the sender connection. ```ballerina - if (senderConnection is asb:SenderConnection) { - log:printInfo("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } + checkpanic asbClient->closeSender(queueSender); ``` - # Samples 1. Send and Receive Message from Queue @@ -388,7 +384,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -417,16 +413,16 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -437,10 +433,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -458,7 +454,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -498,16 +495,18 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(topicSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(subscriptionReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -516,16 +515,16 @@ public function main() { } } } else if (messageReceived is ()) { - log:printError("No message in the queue."); + log:printError("No message in the subscription."); } else { log:printError("Receiving message via Asb receiver connection failed."); } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -543,8 +542,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -573,16 +572,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -593,10 +593,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -615,8 +615,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -656,16 +656,18 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(topicSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(subscriptionReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -680,10 +682,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -701,7 +703,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -730,19 +732,19 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->complete(messageReceived); + checkpanic asbClient->complete(queueReceiver, messageReceived); log:printInfo("Complete message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); @@ -751,10 +753,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -772,8 +774,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -802,19 +804,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->complete(messageReceived); + checkpanic asbClient->complete(subscriptionReceiver, messageReceived); log:printInfo("Complete message successful"); } else if (messageReceived is ()) { log:printError("No message in the subscription."); @@ -823,10 +826,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -845,7 +848,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -874,22 +877,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->abandon(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->abandon(queueReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is asb:Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(queueReceiver, messageReceivedAgain); log:printInfo("Abandon message successful"); } else { log:printError("Abandon message not succesful."); @@ -901,10 +904,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -923,8 +926,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -953,22 +956,23 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->abandon(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->abandon(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is asb:Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(subscriptionReceiver, messageReceivedAgain); log:printInfo("Abandon message successful"); } else { log:printError("Abandon message not succesful."); @@ -980,10 +984,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -1004,7 +1008,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -1032,16 +1036,16 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); asb:Service asyncTestService = @asb:ServiceConfig { entityConfig: { connectionString: connectionString, - entityPath: queuePath + entityPath: queueName } } service object { @@ -1064,7 +1068,7 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); } ``` @@ -1083,7 +1087,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -1112,20 +1116,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->deadLetter(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->deadLetter(queueReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is ()) { log:printInfo("Deadletter message successful"); } else { @@ -1138,10 +1142,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -1160,8 +1164,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -1190,20 +1194,21 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->deadLetter(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->deadLetter(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is ()) { log:printInfo("Deadletter message successful"); } else { @@ -1216,10 +1221,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -1238,7 +1243,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -1267,21 +1272,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - int sequenceNumber = checkpanic asbClient->defer(messageReceived); + int sequenceNumber = checkpanic asbClient->defer(queueReceiver, messageReceived); log:printInfo("Defer message successful"); - asb:Message|asb:Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(sequenceNumber); + asb:Message|asb:Error? messageReceivedAgain = + checkpanic asbClient->receiveDeferred(queueReceiver,sequenceNumber); if (messageReceivedAgain is asb:Message) { log:printInfo("Reading Deferred Message : " + messageReceivedAgain.toString()); } @@ -1292,10 +1298,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -1314,8 +1320,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -1344,21 +1350,23 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - int sequenceNumber = checkpanic asbClient->defer(messageReceived); + int sequenceNumber = checkpanic asbClient->defer(subscriptionReceiver, messageReceived); log:printInfo("Defer message successful"); - asb:Message|asb:Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(sequenceNumber); + asb:Message|asb:Error? messageReceivedAgain = + checkpanic asbClient->receiveDeferred(subscriptionReceiver, sequenceNumber); if (messageReceivedAgain is asb:Message) { log:printInfo("Reading Deferred Message : " + messageReceivedAgain.toString()); } @@ -1369,10 +1377,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -1391,7 +1399,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -1420,25 +1428,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->renewLock(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); - if (messageReceivedAgain is ()) { - log:printInfo("Renew lock message successful"); - } else { - log:printError("Renew lock on message not succesful."); - } + checkpanic asbClient->renewLock(queueReceiver, messageReceived); + log:printInfo("Renew lock message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -1446,10 +1449,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -1468,8 +1471,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -1498,25 +1501,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->renewLock(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); - if (messageReceivedAgain is ()) { - log:printInfo("Renew lock message successful"); - } else { - log:printError("Renew lock on message not succesful."); - } + checkpanic asbClient->renewLock(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); + log:printInfo("Renew lock message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -1524,10 +1524,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` diff --git a/asb-ballerina/Module.md b/asb-ballerina/Module.md index 6e460393..7e5a60b4 100644 --- a/asb-ballerina/Module.md +++ b/asb-ballerina/Module.md @@ -126,14 +126,14 @@ You can now make an Azure service bus client using the connection configuration. ### Step 4: Create a Queue Sender using the Azure service bus client You can now make a sender connection using the Azure service bus client. Provide the `queueName` as a parameter. ```ballerina - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); ``` ### Step 5 : Create a Queue Receiver using the Azure service bus client You can now make a receiver connection using the connection configuration. Provide the `queueName` as a parameter. Optionally you can provide the receive mode which is PEEKLOCK by default. ```ballerina - checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); ``` ### Step 6: Initialize the Input Values @@ -162,13 +162,13 @@ Initialize the message to be sent with message body, optional parameters and pro You can now send a message to the configured azure service bus entity with message body, optional parameters and properties. Here we have shown how to send a text message parsed to the byte array format. ```ballerina - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); ``` ### Step 8: Receive a Message from Azure Service Bus You can now receive a message from the configured azure service bus entity. ```ballerina - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -182,13 +182,13 @@ You can now receive a message from the configured azure service bus entity. ### Step 9: Close Sender Connection You can now close the sender connection. ```ballerina - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); ``` ### Step 10: Close Receiver Connection You can now close the receiver connection. ```ballerina - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); ``` Sample is available at: @@ -222,7 +222,7 @@ You can now make an Azure service bus client using the connection configuration. ### Step 4: Create a Queue Sender using the Azure service bus client You can now make a sender connection using the Azure service bus client. Provide the `queueName` as a parameter. ```ballerina - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); ``` ### Step 5: Initialize the Input Values @@ -251,19 +251,19 @@ Initialize the message to be sent with message body, optional parameters and pro You can now send a message to the configured azure service bus entity with message body, optional parameters and properties. Here we have shown how to send a text message parsed to the byte array format. ```ballerina - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); ``` ### Step 7: Create a service object with the service configuration and the service logic to execute based on the message received You can now create a service object with the service configuration specified using the @asb:ServiceConfig annotation. -We need to give the connection string and the entity path of the queue we are to listen messages from. Then we can give -the service logic to execute when a message is received inside the onMessage remote function. +We need to give the connection string and the entity path of the queue we are to listen messages from. We can optionally provide the receive mode. Default mode is the PEEKLOCK mode. Then we can give the service logic to execute when a message is received inside the onMessage remote function. ```ballerina asb:Service asyncTestService = @asb:ServiceConfig { entityConfig: { connectionString: , - entityPath: + entityPath: , + receiveMode: } } service object { @@ -298,10 +298,7 @@ the connection with the Azure Service Bus. ### Step 8: Close Sender Connection You can now close the sender connection. ```ballerina - if (senderConnection is asb:SenderConnection) { - log:printInfo("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } + checkpanic asbClient->closeSender(queueSender); ``` Sample is available at: @@ -325,7 +322,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -365,16 +362,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(queueSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(queueReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -389,10 +387,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -411,8 +409,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -441,16 +439,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -461,10 +460,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` diff --git a/asb-ballerina/Package.md b/asb-ballerina/Package.md index 6e460393..7e5a60b4 100644 --- a/asb-ballerina/Package.md +++ b/asb-ballerina/Package.md @@ -126,14 +126,14 @@ You can now make an Azure service bus client using the connection configuration. ### Step 4: Create a Queue Sender using the Azure service bus client You can now make a sender connection using the Azure service bus client. Provide the `queueName` as a parameter. ```ballerina - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); ``` ### Step 5 : Create a Queue Receiver using the Azure service bus client You can now make a receiver connection using the connection configuration. Provide the `queueName` as a parameter. Optionally you can provide the receive mode which is PEEKLOCK by default. ```ballerina - checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); ``` ### Step 6: Initialize the Input Values @@ -162,13 +162,13 @@ Initialize the message to be sent with message body, optional parameters and pro You can now send a message to the configured azure service bus entity with message body, optional parameters and properties. Here we have shown how to send a text message parsed to the byte array format. ```ballerina - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); ``` ### Step 8: Receive a Message from Azure Service Bus You can now receive a message from the configured azure service bus entity. ```ballerina - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -182,13 +182,13 @@ You can now receive a message from the configured azure service bus entity. ### Step 9: Close Sender Connection You can now close the sender connection. ```ballerina - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); ``` ### Step 10: Close Receiver Connection You can now close the receiver connection. ```ballerina - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); ``` Sample is available at: @@ -222,7 +222,7 @@ You can now make an Azure service bus client using the connection configuration. ### Step 4: Create a Queue Sender using the Azure service bus client You can now make a sender connection using the Azure service bus client. Provide the `queueName` as a parameter. ```ballerina - checkpanic asbClient->createQueueSender(queueName); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); ``` ### Step 5: Initialize the Input Values @@ -251,19 +251,19 @@ Initialize the message to be sent with message body, optional parameters and pro You can now send a message to the configured azure service bus entity with message body, optional parameters and properties. Here we have shown how to send a text message parsed to the byte array format. ```ballerina - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); ``` ### Step 7: Create a service object with the service configuration and the service logic to execute based on the message received You can now create a service object with the service configuration specified using the @asb:ServiceConfig annotation. -We need to give the connection string and the entity path of the queue we are to listen messages from. Then we can give -the service logic to execute when a message is received inside the onMessage remote function. +We need to give the connection string and the entity path of the queue we are to listen messages from. We can optionally provide the receive mode. Default mode is the PEEKLOCK mode. Then we can give the service logic to execute when a message is received inside the onMessage remote function. ```ballerina asb:Service asyncTestService = @asb:ServiceConfig { entityConfig: { connectionString: , - entityPath: + entityPath: , + receiveMode: } } service object { @@ -298,10 +298,7 @@ the connection with the Azure Service Bus. ### Step 8: Close Sender Connection You can now close the sender connection. ```ballerina - if (senderConnection is asb:SenderConnection) { - log:printInfo("Closing Asb sender connection."); - checkpanic senderConnection.closeSenderConnection(); - } + checkpanic asbClient->closeSender(queueSender); ``` Sample is available at: @@ -325,7 +322,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -365,16 +362,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(queueSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(queueReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -389,10 +387,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -411,8 +409,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -441,16 +439,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -461,10 +460,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` diff --git a/asb-ballerina/samples/README.md b/asb-ballerina/samples/README.md index adefb526..a7ba9ab4 100644 --- a/asb-ballerina/samples/README.md +++ b/asb-ballerina/samples/README.md @@ -14,7 +14,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -43,16 +43,16 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -63,10 +63,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -84,7 +84,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -124,16 +125,18 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(topicSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(subscriptionReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -142,16 +145,16 @@ public function main() { } } } else if (messageReceived is ()) { - log:printError("No message in the queue."); + log:printError("No message in the subscription."); } else { log:printError("Receiving message via Asb receiver connection failed."); } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -169,8 +172,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -199,16 +202,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -219,10 +223,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -241,8 +245,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -282,16 +286,18 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(topicSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(subscriptionReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -306,10 +312,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -327,7 +333,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -356,19 +362,19 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->complete(messageReceived); + checkpanic asbClient->complete(queueReceiver, messageReceived); log:printInfo("Complete message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); @@ -377,10 +383,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -398,8 +404,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -428,19 +434,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->complete(messageReceived); + checkpanic asbClient->complete(subscriptionReceiver, messageReceived); log:printInfo("Complete message successful"); } else if (messageReceived is ()) { log:printError("No message in the subscription."); @@ -449,10 +456,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -471,7 +478,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -500,22 +507,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->abandon(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->abandon(queueReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is asb:Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(queueReceiver, messageReceivedAgain); log:printInfo("Abandon message successful"); } else { log:printError("Abandon message not succesful."); @@ -527,10 +534,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -549,8 +556,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -579,22 +586,23 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->abandon(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->abandon(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is asb:Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(subscriptionReceiver, messageReceivedAgain); log:printInfo("Abandon message successful"); } else { log:printError("Abandon message not succesful."); @@ -606,10 +614,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -630,7 +638,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -658,16 +666,16 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); asb:Service asyncTestService = @asb:ServiceConfig { entityConfig: { connectionString: connectionString, - entityPath: queuePath + entityPath: queueName } } service object { @@ -690,7 +698,7 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); } ``` @@ -709,7 +717,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -738,20 +746,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->deadLetter(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->deadLetter(queueReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is ()) { log:printInfo("Deadletter message successful"); } else { @@ -764,10 +772,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -786,8 +794,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -816,20 +824,21 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->deadLetter(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->deadLetter(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is ()) { log:printInfo("Deadletter message successful"); } else { @@ -842,10 +851,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -864,7 +873,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -893,21 +902,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - int sequenceNumber = checkpanic asbClient->defer(messageReceived); + int sequenceNumber = checkpanic asbClient->defer(queueReceiver, messageReceived); log:printInfo("Defer message successful"); - asb:Message|asb:Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(sequenceNumber); + asb:Message|asb:Error? messageReceivedAgain = + checkpanic asbClient->receiveDeferred(queueReceiver,sequenceNumber); if (messageReceivedAgain is asb:Message) { log:printInfo("Reading Deferred Message : " + messageReceivedAgain.toString()); } @@ -918,10 +928,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -940,8 +950,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -970,21 +980,23 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - int sequenceNumber = checkpanic asbClient->defer(messageReceived); + int sequenceNumber = checkpanic asbClient->defer(subscriptionReceiver, messageReceived); log:printInfo("Defer message successful"); - asb:Message|asb:Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(sequenceNumber); + asb:Message|asb:Error? messageReceivedAgain = + checkpanic asbClient->receiveDeferred(subscriptionReceiver, sequenceNumber); if (messageReceivedAgain is asb:Message) { log:printInfo("Reading Deferred Message : " + messageReceivedAgain.toString()); } @@ -995,10 +1007,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` @@ -1017,7 +1029,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -1046,25 +1058,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->renewLock(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); - if (messageReceivedAgain is ()) { - log:printInfo("Renew lock message successful"); - } else { - log:printError("Renew lock on message not succesful."); - } + checkpanic asbClient->renewLock(queueReceiver, messageReceived); + log:printInfo("Renew lock message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -1072,10 +1079,10 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } ``` @@ -1094,8 +1101,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -1124,25 +1131,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->renewLock(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); - if (messageReceivedAgain is ()) { - log:printInfo("Renew lock message successful"); - } else { - log:printError("Renew lock on message not succesful."); - } + checkpanic asbClient->renewLock(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); + log:printInfo("Renew lock message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -1150,9 +1154,9 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } ``` diff --git a/asb-ballerina/samples/abandon_message_from_queue.bal b/asb-ballerina/samples/abandon_message_from_queue.bal index 05f20194..346c9865 100644 --- a/asb-ballerina/samples/abandon_message_from_queue.bal +++ b/asb-ballerina/samples/abandon_message_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,22 +48,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->abandon(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->abandon(queueReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is asb:Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(queueReceiver, messageReceivedAgain); log:printInfo("Abandon message successful"); } else { log:printError("Abandon message not succesful."); @@ -75,8 +75,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/abandon_message_from_subscription.bal b/asb-ballerina/samples/abandon_message_from_subscription.bal index cad6bf16..8a75d828 100644 --- a/asb-ballerina/samples/abandon_message_from_subscription.bal +++ b/asb-ballerina/samples/abandon_message_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -49,22 +49,23 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->abandon(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->abandon(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is asb:Message) { - checkpanic asbClient->complete(messageReceivedAgain); + checkpanic asbClient->complete(subscriptionReceiver, messageReceivedAgain); log:printInfo("Abandon message successful"); } else { log:printError("Abandon message not succesful."); @@ -76,8 +77,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-ballerina/samples/async_consumer.bal b/asb-ballerina/samples/async_consumer.bal index cb93bbd1..9da1dd2a 100644 --- a/asb-ballerina/samples/async_consumer.bal +++ b/asb-ballerina/samples/async_consumer.bal @@ -20,7 +20,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,16 +48,16 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); asb:Service asyncTestService = @asb:ServiceConfig { entityConfig: { connectionString: connectionString, - entityPath: queuePath + entityPath: queueName } } service object { @@ -80,5 +80,5 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); } diff --git a/asb-ballerina/samples/complete_message_from_queue.bal b/asb-ballerina/samples/complete_message_from_queue.bal index 85221f01..123733aa 100644 --- a/asb-ballerina/samples/complete_message_from_queue.bal +++ b/asb-ballerina/samples/complete_message_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,19 +48,19 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->complete(messageReceived); + checkpanic asbClient->complete(queueReceiver, messageReceived); log:printInfo("Complete message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); @@ -69,8 +69,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/complete_message_from_subscription.bal b/asb-ballerina/samples/complete_message_from_subscription.bal index c0a99af4..c30e0b71 100644 --- a/asb-ballerina/samples/complete_message_from_subscription.bal +++ b/asb-ballerina/samples/complete_message_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -49,19 +49,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->complete(messageReceived); + checkpanic asbClient->complete(subscriptionReceiver, messageReceived); log:printInfo("Complete message successful"); } else if (messageReceived is ()) { log:printError("No message in the subscription."); @@ -70,8 +71,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-ballerina/samples/deadletter_from_queue.bal b/asb-ballerina/samples/deadletter_from_queue.bal index 852a612f..957bcd3a 100644 --- a/asb-ballerina/samples/deadletter_from_queue.bal +++ b/asb-ballerina/samples/deadletter_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,20 +48,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->deadLetter(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->deadLetter(queueReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceivedAgain is ()) { log:printInfo("Deadletter message successful"); } else { @@ -74,8 +74,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/deadletter_from_subscription.bal b/asb-ballerina/samples/deadletter_from_subscription.bal index 02f13620..e0ad7307 100644 --- a/asb-ballerina/samples/deadletter_from_subscription.bal +++ b/asb-ballerina/samples/deadletter_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -49,20 +49,21 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->deadLetter(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); + checkpanic asbClient->deadLetter(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceivedAgain is ()) { log:printInfo("Deadletter message successful"); } else { @@ -75,8 +76,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-ballerina/samples/defer_from_queue.bal b/asb-ballerina/samples/defer_from_queue.bal index e4caa6b4..0ca2ac25 100644 --- a/asb-ballerina/samples/defer_from_queue.bal +++ b/asb-ballerina/samples/defer_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,21 +48,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - int sequenceNumber = checkpanic asbClient->defer(messageReceived); + int sequenceNumber = checkpanic asbClient->defer(queueReceiver, messageReceived); log:printInfo("Defer message successful"); - asb:Message|asb:Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(sequenceNumber); + asb:Message|asb:Error? messageReceivedAgain = + checkpanic asbClient->receiveDeferred(queueReceiver,sequenceNumber); if (messageReceivedAgain is asb:Message) { log:printInfo("Reading Deferred Message : " + messageReceivedAgain.toString()); } @@ -73,8 +74,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/defer_from_subscription.bal b/asb-ballerina/samples/defer_from_subscription.bal index e974bb8f..8a7c0e9b 100644 --- a/asb-ballerina/samples/defer_from_subscription.bal +++ b/asb-ballerina/samples/defer_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -49,21 +49,23 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - int sequenceNumber = checkpanic asbClient->defer(messageReceived); + int sequenceNumber = checkpanic asbClient->defer(subscriptionReceiver, messageReceived); log:printInfo("Defer message successful"); - asb:Message|asb:Error? messageReceivedAgain = checkpanic asbClient->receiveDeferred(sequenceNumber); + asb:Message|asb:Error? messageReceivedAgain = + checkpanic asbClient->receiveDeferred(subscriptionReceiver, sequenceNumber); if (messageReceivedAgain is asb:Message) { log:printInfo("Reading Deferred Message : " + messageReceivedAgain.toString()); } @@ -74,8 +76,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-ballerina/samples/renew_lock_on_message_from_queue.bal b/asb-ballerina/samples/renew_lock_on_message_from_queue.bal index cdf7cd11..aa605946 100644 --- a/asb-ballerina/samples/renew_lock_on_message_from_queue.bal +++ b/asb-ballerina/samples/renew_lock_on_message_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,25 +48,20 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:PEEKLOCK); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->renewLock(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); - if (messageReceivedAgain is ()) { - log:printInfo("Renew lock message successful"); - } else { - log:printError("Renew lock on message not succesful."); - } + checkpanic asbClient->renewLock(queueReceiver, messageReceived); + log:printInfo("Renew lock message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -74,8 +69,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal b/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal index 389d55e7..cf47c646 100644 --- a/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal +++ b/asb-ballerina/samples/renew_lock_on_message_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -49,25 +49,22 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:PEEKLOCK); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:PEEKLOCK); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { - checkpanic asbClient->renewLock(messageReceived); - asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(serverWaitTime); - if (messageReceivedAgain is ()) { - log:printInfo("Renew lock message successful"); - } else { - log:printError("Renew lock on message not succesful."); - } + checkpanic asbClient->renewLock(subscriptionReceiver, messageReceived); + asb:Message|asb:Error? messageReceivedAgain = asbClient->receive(subscriptionReceiver, serverWaitTime); + log:printInfo("Renew lock message successful"); } else if (messageReceived is ()) { log:printError("No message in the queue."); } else { @@ -75,8 +72,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-ballerina/samples/send_and_receive_batch_from_queue.bal b/asb-ballerina/samples/send_and_receive_batch_from_queue.bal index acfb6aab..68f1eef5 100644 --- a/asb-ballerina/samples/send_and_receive_batch_from_queue.bal +++ b/asb-ballerina/samples/send_and_receive_batch_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -59,16 +59,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(queueSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(queueReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -83,8 +84,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/send_and_receive_message_from_queue.bal b/asb-ballerina/samples/send_and_receive_message_from_queue.bal index db750d2e..eca341ad 100644 --- a/asb-ballerina/samples/send_and_receive_message_from_queue.bal +++ b/asb-ballerina/samples/send_and_receive_message_from_queue.bal @@ -19,7 +19,7 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string queuePath = ?; +configurable string queueName = ?; public function main() { @@ -48,16 +48,16 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createQueueSender(queuePath); + handle queueSender = checkpanic asbClient->createQueueSender(queueName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createQueueReceiver(queuePath, asb:RECEIVEANDDELETE); + handle queueReceiver = checkpanic asbClient->createQueueReceiver(queueName, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(queueSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(queueReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -68,8 +68,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(queueSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(queueReceiver); } diff --git a/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal b/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal index db6db8c2..824000a8 100644 --- a/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal +++ b/asb-ballerina/samples/send_batch_to_topic_and_receive_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -60,16 +60,18 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->sendBatch(messages); + checkpanic asbClient->sendBatch(topicSender, messages); log:printInfo("Receiving from Asb receiver connection."); - asb:MessageBatch|asb:Error? messageReceived = asbClient->receiveBatch(maxMessageCount, serverWaitTime); + asb:MessageBatch|asb:Error? messageReceived = + asbClient->receiveBatch(subscriptionReceiver, maxMessageCount, serverWaitTime); if (messageReceived is asb:MessageBatch) { foreach asb:Message message in messageReceived.messages { @@ -84,8 +86,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } diff --git a/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal b/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal index 8b79cc06..f06eed60 100644 --- a/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal +++ b/asb-ballerina/samples/send_to_topic_and_receive_from_subscription.bal @@ -19,8 +19,8 @@ import ballerinax/asb; // Connection Configurations configurable string connectionString = ?; -configurable string topicPath = ?; -configurable string subscriptionPath1 = ?; +configurable string topicName = ?; +configurable string subscriptionName1 = ?; public function main() { @@ -49,16 +49,17 @@ public function main() { asb:AsbClient asbClient = new (config); log:printInfo("Creating Asb sender connection."); - checkpanic asbClient->createTopicSender(topicPath); + handle topicSender = checkpanic asbClient->createTopicSender(topicName); log:printInfo("Creating Asb receiver connection."); - checkpanic asbClient->createSubscriptionReceiver(subscriptionPath1, asb:RECEIVEANDDELETE); + handle subscriptionReceiver = + checkpanic asbClient->createSubscriptionReceiver(topicName, subscriptionName1, asb:RECEIVEANDDELETE); log:printInfo("Sending via Asb sender connection."); - checkpanic asbClient->send(message1); + checkpanic asbClient->send(topicSender, message1); log:printInfo("Receiving from Asb receiver connection."); - asb:Message|asb:Error? messageReceived = asbClient->receive(serverWaitTime); + asb:Message|asb:Error? messageReceived = asbClient->receive(subscriptionReceiver, serverWaitTime); if (messageReceived is asb:Message) { log:printInfo("Reading Received Message : " + messageReceived.toString()); @@ -69,8 +70,8 @@ public function main() { } log:printInfo("Closing Asb sender connection."); - checkpanic asbClient->closeSender(); + checkpanic asbClient->closeSender(topicSender); log:printInfo("Closing Asb receiver connection."); - checkpanic asbClient->closeReceiver(); + checkpanic asbClient->closeReceiver(subscriptionReceiver); } From a5d5f6adcbb03481dffede2951ac69e6c17f0b50 Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Thu, 6 May 2021 02:40:00 +0530 Subject: [PATCH 7/8] Migrate to SLAlpha5 --- README.md | 6 +++--- asb-ballerina/Dependencies.toml | 6 +++--- asb-ballerina/Module.md | 6 +++--- asb-ballerina/Package.md | 6 +++--- asb-ballerina/client.bal | 1 + asb-native/pom.xml | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index af1179ee..3f5771b2 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 SLAlpha4 Installed - Ballerina Swan Lake Alpha 4 is required. +* Ballerina SLAlpha5 Installed + Ballerina Swan Lake Alpha 5 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-Alpha4 | +| Ballerina Language | Swan-Lake-Alpha5 | | Service Bus API | v3.5.1 | # Quickstart(s) diff --git a/asb-ballerina/Dependencies.toml b/asb-ballerina/Dependencies.toml index 1e56e1c5..039fa6aa 100644 --- a/asb-ballerina/Dependencies.toml +++ b/asb-ballerina/Dependencies.toml @@ -6,16 +6,16 @@ version = "0.0.0" [[dependency]] org = "ballerina" name = "time" -version = "2.0.0-alpha8" +version = "2.0.0-alpha9" [[dependency]] org = "ballerina" name = "log" -version = "1.1.0-alpha7" +version = "1.1.0-alpha8" [[dependency]] org = "ballerina" name = "os" -version = "0.8.0-alpha7" +version = "0.8.0-alpha8" diff --git a/asb-ballerina/Module.md b/asb-ballerina/Module.md index 7e5a60b4..b7c6042a 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-Alpha4 | +| Ballerina Language | Swan-Lake-Alpha5 | | Service Bus API | v3.5.1 | # Supported Operations @@ -56,8 +56,8 @@ immediate stop listening. * Java 11 Installed Java Development Kit (JDK) with version 11 is required. -* Ballerina SLAlpha4 Installed - Ballerina Swan Lake Alpha 4 is required. +* Ballerina SLAlpha5 Installed + Ballerina Swan Lake Alpha 5 is required. * Shared Access Signature (SAS) Authentication Credentials * Connection String diff --git a/asb-ballerina/Package.md b/asb-ballerina/Package.md index 7e5a60b4..b7c6042a 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-Alpha4 | +| Ballerina Language | Swan-Lake-Alpha5 | | Service Bus API | v3.5.1 | # Supported Operations @@ -56,8 +56,8 @@ immediate stop listening. * Java 11 Installed Java Development Kit (JDK) with version 11 is required. -* Ballerina SLAlpha4 Installed - Ballerina Swan Lake Alpha 4 is required. +* Ballerina SLAlpha5 Installed + Ballerina Swan Lake Alpha 5 is required. * Shared Access Signature (SAS) Authentication Credentials * Connection String diff --git a/asb-ballerina/client.bal b/asb-ballerina/client.bal index 5f17047e..306f34e0 100644 --- a/asb-ballerina/client.bal +++ b/asb-ballerina/client.bal @@ -301,6 +301,7 @@ public client class AsbClient { # The operation renews lock on a message in a queue or subscription based on messageLockToken. # # + asbReceiver - Asb Receiver + # + message - Message record # + return - An `asb:Error` if failed to renew message or else `()` @display {label: "Renew Lock on Message"} isolated remote function renewLock(@display {label: "Asb Receiver"} handle asbReceiver, diff --git a/asb-native/pom.xml b/asb-native/pom.xml index dc8730f5..00d406b0 100644 --- a/asb-native/pom.xml +++ b/asb-native/pom.xml @@ -81,13 +81,13 @@ org.ballerinalang ballerina-runtime - 2.0.0-alpha7-20210403-234900-bdd55df1 + 2.0.0-alpha8-20210423-135000-530658ec provided org.ballerinalang ballerina-lang - 2.0.0-alpha7-20210403-234900-bdd55df1 + 2.0.0-alpha8-20210423-135000-530658ec provided From 0585c5add1969781bacb1839685732ce1e588f1f Mon Sep 17 00:00:00 2001 From: RolandHewage Date: Thu, 6 May 2021 02:51:26 +0530 Subject: [PATCH 8/8] Update github workflow --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/pull-request.yml | 10 +++++----- .github/workflows/release.yml | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15dff401..4429fccd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,8 +72,8 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }} - QUEUE_PATH: ${{ secrets.QUEUE_NAME }} - TOPIC_PATH: ${{ secrets.TOPIC_NAME }} - SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_NAME1 }} - SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_NAME2 }} - SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_NAME3 }} + QUEUE_NAME: ${{ secrets.QUEUE_NAME }} + TOPIC_NAME: ${{ secrets.TOPIC_NAME }} + SUBSCRIPTION_NAME1: ${{ secrets.SUBSCRIPTION_NAME1 }} + SUBSCRIPTION_NAME2: ${{ secrets.SUBSCRIPTION_NAME2 }} + SUBSCRIPTION_NAME3: ${{ secrets.SUBSCRIPTION_NAME3 }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8b4163a9..03fca4b9 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -72,8 +72,8 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }} - QUEUE_PATH: ${{ secrets.QUEUE_NAME }} - TOPIC_PATH: ${{ secrets.TOPIC_NAME }} - SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_NAME1 }} - SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_NAME2 }} - SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_NAME3 }} + QUEUE_NAME: ${{ secrets.QUEUE_NAME }} + TOPIC_NAME: ${{ secrets.TOPIC_NAME }} + SUBSCRIPTION_NAME1: ${{ secrets.SUBSCRIPTION_NAME1 }} + SUBSCRIPTION_NAME2: ${{ secrets.SUBSCRIPTION_NAME2 }} + SUBSCRIPTION_NAME3: ${{ secrets.SUBSCRIPTION_NAME3 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f69e57ed..141e1167 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,11 +74,11 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }} - QUEUE_PATH: ${{ secrets.QUEUE_NAME }} - TOPIC_PATH: ${{ secrets.TOPIC_NAME }} - SUBSCRIPTION_PATH1: ${{ secrets.SUBSCRIPTION_NAME1 }} - SUBSCRIPTION_PATH2: ${{ secrets.SUBSCRIPTION_NAME2 }} - SUBSCRIPTION_PATH3: ${{ secrets.SUBSCRIPTION_NAME3 }} + QUEUE_NAME: ${{ secrets.QUEUE_NAME }} + TOPIC_NAME: ${{ secrets.TOPIC_NAME }} + SUBSCRIPTION_NAME1: ${{ secrets.SUBSCRIPTION_NAME1 }} + SUBSCRIPTION_NAME2: ${{ secrets.SUBSCRIPTION_NAME2 }} + SUBSCRIPTION_NAME3: ${{ secrets.SUBSCRIPTION_NAME3 }} # Push to Ballerina Central - name: Ballerina Push