Skip to content

Commit

Permalink
Merge pull request #124 from SanduDS/main
Browse files Browse the repository at this point in the history
Revamp the connector to latest ASB SDK 7.13.1
  • Loading branch information
LakshanSS authored Feb 1, 2023
2 parents 36fb36e + efbd10f commit d087d53
Show file tree
Hide file tree
Showing 20 changed files with 670 additions and 1,182 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dev-stg-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
./gradlew build
- name: Ballerina Build
uses: ballerina-platform/ballerina-action/@2201.2.1
uses: ballerina-platform/ballerina-action/@2201.3.1
with:
args:
pack ./asb-ballerina
Expand All @@ -46,7 +46,7 @@ jobs:

- name: Push to Staging
if: github.event.inputs.bal_central_environment == 'STAGE'
uses: ballerina-platform/ballerina-action/@2201.2.1
uses: ballerina-platform/ballerina-action/@2201.3.1
with:
args:
push
Expand All @@ -57,7 +57,7 @@ jobs:

- name: Push to Dev
if: github.event.inputs.bal_central_environment == 'DEV'
uses: ballerina-platform/ballerina-action/@2201.2.1
uses: ballerina-platform/ballerina-action/@2201.3.1
with:
args:
push
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# Build Ballerina Project
- name: Ballerina Build
uses: ballerina-platform/ballerina-action/@2201.2.1
uses: ballerina-platform/ballerina-action/@2201.3.1
with:
args:
pack ./asb-ballerina
Expand All @@ -56,7 +56,7 @@ jobs:

# Push to Ballerina Central
- name: Ballerina Push
uses: ballerina-platform/ballerina-action/@2201.2.1
uses: ballerina-platform/ballerina-action/@2201.3.1
with:
args:
push
Expand Down
8 changes: 4 additions & 4 deletions asb-ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
distribution = "2201.3.0"
distribution = "2201.3.1"
org = "ballerinax"
name = "asb"
version = "2.4.0"
version = "3.0.0"
license= ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["IT Operations/Message Brokers", "Cost/Paid", "Vendor/Microsoft"]
Expand All @@ -13,8 +13,8 @@ repository = "https://github.com/ballerina-platform/module-ballerinax-azure-serv
observabilityIncluded = true

[[platform.java11.dependency]]
path = "../asb-native/build/libs/asb-native-2.4.0.jar"
path = "../asb-native/build/libs/asb-native-3.0.0.jar"
groupId = "org.ballerinax"
artifactId = "asb-native"
module = "asb-native"
version = "2.4.0"
version = "3.0.0"
23 changes: 11 additions & 12 deletions asb-ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ applies [SAS authentication](https://docs.microsoft.com/en-us/azure/service-bus-
supports SAS authentication as well.

This module
supports [Service Bus SDK 3.5.1 version](https://docs.microsoft.com/en-us/java/api/overview/azure/servicebus/client?view=azure-java-stable&preserve-view=true)
supports [Service Bus SDK 7.13.1 version](https://learn.microsoft.com/en-us/java/api/overview/azure/service-bus?view=azure-java-stable#libraries-for-data-access)
. The source code on GitHub is
located [here](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/servicebus/microsoft-azure-servicebus). The
located [here](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/servicebus/azure-messaging-servicebus). The
primary wire protocol for Service Bus is Advanced Messaging Queueing Protocol (AMQP) 1.0, an open ISO/IEC standard.

## Prerequisites
Expand All @@ -43,7 +43,6 @@ Before using this connector in your Ballerina application, complete the followin

Shared Access Signature (SAS) Authentication Credentials are required to communicate with the Azure Service Bus.
* Connection String
* Entity Path

Obtain the authorization credentials:
* For Service Bus Queues
Expand All @@ -52,7 +51,7 @@ Before using this connector in your Ballerina application, complete the followin

2. [Get the connection string](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-portal#get-the-connection-string)

3. [Create a queue in the Azure portal & get Entity Path](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-portal#create-a-queue-in-the-azure-portal)
3. [Create a queue in the Azure portal & get queue name](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-portal#create-a-queue-in-the-azure-portal)
. It is in the format ‘queueName’.

* For Service Bus Topics and Subscriptions
Expand All @@ -61,10 +60,10 @@ Before using this connector in your Ballerina application, complete the followin

2. [Get the connection string](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-portal#get-the-connection-string)

3. [Create a topic in the Azure portal & get Entity Path](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-topics-subscriptions-portal#create-a-topic-using-the-azure-portal)
3. [Create a topic in the Azure portal & get topic name](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-topics-subscriptions-portal#create-a-topic-using-the-azure-portal)
. It's in the format ‘topicName‘.

4. [Create a subscription in the Azure portal & get Entity Path](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-topics-subscriptions-portal#create-subscriptions-to-the-topic)
4. [Create a subscription in the Azure portal & get its name](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-topics-subscriptions-portal#create-subscriptions-to-the-topic)
. It’s in the format ‘topicName/subscriptions/subscriptionName’.

## Quickstart
Expand All @@ -86,8 +85,8 @@ import ballerinax/asb as asb;
This can be done providing connection string with queue or topic name.

```ballerina
asb:MessageSender queueSender = check new (connectionString, queueName);
asb:MessageSender topicSender = check new (connectionString, TopicName);
asb:MessageSender queueSender = check new (senderConfig);
asb:MessageSender topicSender = check new (senderConfig);
```

#### Initialize a Message Receiver client
Expand All @@ -96,8 +95,8 @@ This can be done providing connection string with queue name, topic name or subs
optional. (Default : PEEKLOCK)

```ballerina
asb:MessageReceiver queueReceiver = check new (connectionString, queueName);
asb:MessageReceiver subscriptionReceiver = check new (connectionString, subscriptionPath);
asb:MessageReceiver queueReceiver = check new (receiverConfig);
asb:MessageReceiver subscriptionReceiver = check new (receiverConfig);
```

### Step 3: Invoke connector operation
Expand All @@ -110,7 +109,7 @@ asb:MessageReceiver subscriptionReceiver = check new (connectionString, subscrip

```ballerina
public function main() returns error? {
asb:MessageSender queueSender = check new (connectionString, queueName);
asb:MessageSender queueSender = check new (senderConfig);
string stringContent = "This is My Message Body";
byte[] byteContent = stringContent.toBytes();
Expand Down Expand Up @@ -142,7 +141,7 @@ asb:MessageReceiver subscriptionReceiver = check new (connectionString, subscrip
```ballerina
public function main() returns error? {
asb:MessageReceiver queueReceiver = check new (connectionString, queueName, asb:RECEIVEANDDELETE);
asb:MessageReceiver queueReceiver = check new (receiverConfig);
int serverWaitTime = 60; // In seconds
Expand Down
4 changes: 2 additions & 2 deletions asb-ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This package provides the capability to easily access Microsoft Azure Service Bu

| | Version |
|----------------------------|-----------------------|
| Ballerina Language | Swan Lake 2201.3.0 |
| Azure Service Bus SDK | 3.5.1 |
| Ballerina Language | Swan Lake 2201.3.1 |
| Azure Service Bus SDK | 7.13.1 |

## Report issues

Expand Down
100 changes: 77 additions & 23 deletions asb-ballerina/commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,17 @@
import ballerina/jballerina.java as java;

// Default values
public const int DEFAULT_TIME_TO_LIVE = 300; // In seconds
public const int DEFAULT_MAX_MESSAGE_COUNT = 1;
public const int DEFAULT_SERVER_WAIT_TIME = 300; // In seconds
public const string DEFAULT_MESSAGE_LOCK_TOKEN = "00000000-0000-0000-0000-000000000000";
public const DEFAULT_TIME_TO_LIVE = 300; // In seconds
public const DEFAULT_MAX_MESSAGE_COUNT = 1;
public const DEFAULT_SERVER_WAIT_TIME = 300; // In seconds
public const DEFAULT_MESSAGE_LOCK_TOKEN = "00000000-0000-0000-0000-000000000000";
public const EMPTY_STRING = "";

// Message content types
public const string TEXT = "text/plain";
public const string JSON = "application/json";
public const string XML = "application/xml";
public const string BYTE_ARRAY = "application/octet-stream";

// Message receive modes
@display {label: "Receive Modes"}
public enum receiveModes {
@display {label: "PEEKLOCK"}
PEEKLOCK,
@display {label: "RECEIVEANDDELETE"}
RECEIVEANDDELETE
}
public const TEXT = "text/plain";
public const JSON = "application/json";
public const XML = "application/xml";
public const BYTE_ARRAY = "application/octet-stream";

// Azure Service Bus Client API Record Types.

Expand All @@ -46,12 +38,74 @@ public enum receiveModes {
# Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;
# SharedAccessKeyName=SHARED_ACCESS_KEY_NAME;SharedAccessKey=SHARED_ACCESS_KEY or
# Endpoint=sb://namespace_DNS_Name;EntityPath=EVENT_HUB_NAME;
# SharedAccessSignatureToken=SHARED_ACCESS_SIGNATURE_TOKEN
@display {label: "Connection Config"}
public type AsbConnectionConfiguration record {|
@display {label: "Connection String"}
# SharedAccessSignatureToken=SHARED_ACCESS_SIGNATURE_TOKEN
# + entityConfig - This field holds the configuration details of either a topic or a queue. The type of the entity is
# determined by the entityType field. The actual configuration details are stored in either a
# TopicSubsConfig or a QueueConfig record
# + receiveMode - This field holds the receive modes(RECEIVE_AND_DELETE/PEEK_LOCK) for the connection. The receive mode determines how messages are
# retrieved from the entity. The default value is PEEK_LOCK
@display {label: "Receiver Connection Config"}
public type ASBServiceReceiverConfig record {
@display {label: "Entity Configuration"}
TopicSubsConfig|QueueConfig entityConfig;
@display {label: "ConnectionString"}
string connectionString;
@display {label: "Receive Mode"}
ReceiveMode receiveMode = PEEK_LOCK;
};

# This record holds the configuration details of a topic and its associated subscription in Azure Service Bus
#
# + topicName - A string field that holds the name of the topic
# + subscriptionName - A string field that holds the name of the subscription associated with the topic
@display {label: "Topic/Subscriptions Configurations"}
public type TopicSubsConfig record {
@display {label: "Topic Name"}
string topicName;
@display {label: "Subscription Name"}
string subscriptionName;
};

# This record holds the configuration details of a queue in Azure Service Bus
#
# + queueName - A string field that holds the name of the queue
@display {label: "Queue Configurations"}
public type QueueConfig record {
@display {label: "Queue Name"}
string queueName;
};

# Holds the configuration details needed to create a sender connection to Azure Service Bus
#
# + entityType - An enumeration value of type EntityType, which specifies whether the connection is for a topic or a queue.
# The valid values are TOPIC and QUEUE
# + topicOrQueueName - A string field that holds the name of the topic or queue
# + connectionString - A string field that holds the Service Bus connection string with Shared Access Signatures.
@display {label: "Sender Connection Config"}
public type ASBServiceSenderConfig record {
@display {label: "EntityType"}
EntityType entityType;
@display {label: "Queue/Topic Name"}
string topicOrQueueName;
@display {label: "ConnectionString"}
string connectionString;
|};
};

//Message entity types
public enum EntityType {
@display {label: "Queue"}
QUEUE = "queue",
@display {label: "Topic"}
TOPIC = "topic"
}

//Message receiver modes
public enum ReceiveMode {
@display {label: "RECEIVE AND DELETE"}
RECEIVE_AND_DELETE = "RECEIVEANDDELETE",
@display {label: "PEEK LOCK"}
PEEK_LOCK = "PEEKLOCK"
}

isolated function nativeGetTextContent(byte[] messageContent) returns string|Error =
@java:Method {
Expand Down Expand Up @@ -81,4 +135,4 @@ isolated function nativeGetXMLContent(byte[] messageContent) returns xml|Error =
@java:Method {
name: "getXMLContent",
'class: "org.ballerinax.asb.util.ASBUtils"
} external;
} external;
6 changes: 1 addition & 5 deletions asb-ballerina/errors.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@
// under the License.

# Represents the Asb module related errors.
public type AsbError distinct error;

# The union of the Asb module related errors.
public type Error AsbError;

public type Error distinct error;
7 changes: 5 additions & 2 deletions asb-ballerina/message.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

# Azure service bus Message representation.
#
# + body - Message body
# + body - Message body, Here the connector supports AMQP message body types - DATA and VALUE, However, DATA type message bodies
# will be received in Ballerina Byte[] type. VALUE message bodies can be any primitive AMQP type. therefore, the connector
# supports for string, int or byte[]. Please refer Azure docs (https://learn.microsoft.com/en-us/java/api/com.azure.core.amqp.models.amqpmessagebody?view=azure-java-stable)
# and AMQP docs (https://qpid.apache.org/amqp/type-reference.html#PrimitiveTypes)
# + contentType - Message content type
# + messageId - Message Id (optional)
# + to - Message to (optional)
Expand All @@ -33,7 +36,7 @@
@display {label: "Message"}
public type Message record {|
@display {label: "Body"}
string|xml|json|byte[] body;
string|int|byte[] body;
@display {label: "Content Type"}
string contentType = TEXT;
@display {label: "Message Id"}
Expand Down
Loading

0 comments on commit d087d53

Please sign in to comment.