Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove listener as trigger.asb is available as a separate package #109

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 1 addition & 47 deletions asb-ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,53 +159,7 @@ asb:MessageReceiver subscriptionReceiver = check new (connectionString, subscrip
check queueReceiver->close();
}
```

Following is an example on how to asynchronously listen to messages from the Azure Service Bus using the listener.
You need to create a new listener instance before listening. Then, you need to create a service object with the
service configuration specified using the `@asb:ServiceConfig` annotation and attach it to the listener. You 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. You can find more information about the receive modes
[here](https://docs.microsoft.com/en-us/java/api/com.microsoft.azure.servicebus.receivemode?view=azure-java-stable).
Finally, you can provide the service logic to execute when a message is received inside the onMessage remote
function.

Listen to Messages from the Azure Service Bus

**!!! NOTE:**
When configuring the listener, the entity path for a Queue is the entity name (Eg: "myQueueName") and the entity path
for a subscription is in the following format `<topicName>/subscriptions/<subscriptionName>`
(Eg: "myTopicName/subscriptions/mySubscriptionName").

```ballerina
listener asb:Listener asbListener = new (connectionString, queueName, asb:PEEKLOCK);

service asb:Service on asbListener {
remote function onMessage(asb:Message message, asb:Caller caller) returns error? {
// Write your logic here
log:printInfo("Azure service bus message as byte[] which is the standard according to the AMQP protocol" +
message.toString());
string|xml|json|byte[] received = message.body;

match message?.contentType {
asb:JSON => {
string stringMessage = check string:fromBytes(<byte[]> received);
json jsonMessage = check value:fromJsonString(stringMessage);
log:printInfo("The message received: " + jsonMessage.toJsonString());
}
asb:XML => {
string stringMessage = check 'string:fromBytes(<byte[]> received);
xml xmlMessage = check 'xml:fromString(stringMessage);
log:printInfo("The message received: " + xmlMessage.toString());
}
asb:TEXT => {
string stringMessage = check 'string:fromBytes(<byte[]> received);
log:printInfo("The message received: " + stringMessage);
}
}
}
};
```


**!!! NOTE:**
Currently we are using the asb:Message record for both sender & receiver operations. When we use the ASB receiver
connector instead of the ASB listener to receive messages we return the exact message converted (re-engineered) to
Expand Down
172 changes: 0 additions & 172 deletions asb-ballerina/caller.bal

This file was deleted.

33 changes: 0 additions & 33 deletions asb-ballerina/commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,6 @@ public type AsbConnectionConfiguration record {|
string connectionString;
|};

// Listener API Record Types and Annotations.

# Configurations used to create a `asb:Connection`.
#
# + connectionString - Service bus connection string with Shared Access Signatures
# ConnectionString format:
# 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
# + entityPath - Entitypath to the message broker resource
# + receiveMode - Message receive modes (optional)
@display {label: "Entity Config"}
public type EntityConfiguration record {|
@display {label: "Connection String"}
string connectionString;
@display {label: "Entity Path"}
string entityPath;
@display {label: "Receive Mode"}
string receiveMode?;
|};

# Service configurations used to create a `asb:Connection`.
#
# + entityConfig - Configurations used to create a `asb:Connection`
@display {label: "Connection Config"}
public type asbServiceConfig record {|
EntityConfiguration entityConfig;
|};

# The annotation, which is used to configure the subscription.
public annotation asbServiceConfig ServiceConfig on service;

isolated function nativeGetTextContent(byte[] messageContent) returns string|Error =
@java:Method {
name: "getTextContent",
Expand Down
112 changes: 0 additions & 112 deletions asb-ballerina/listener.bal

This file was deleted.

Loading