Skip to content

Commit

Permalink
Merge pull request #229 from ayeshLK/getting-started-guide
Browse files Browse the repository at this point in the history
Add quickstart instructions for ASB listener-svc implementation
  • Loading branch information
NipunaRanasinghe authored Jun 5, 2024
2 parents 3715094 + 2f35ed1 commit d4cb689
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ This can be done by providing a connection string with a queue name, topic name,
asb:MessageReceiver asbReceiver = check new (receiverConfig);
```

#### Initialize a message listener

This can be done by providing a connection string with a queue name, topic name, or subscription path.

> Here, the Receive mode is optional. (Default: PEEKLOCK)
```ballerina
configurable string connectionString = ?;
listener asb:Listener asbListener = check new (
connectionString = connectionString,
entityConfig = {
queueName: "myQueue"
}
);
```

### Step 3: Invoke connector operation

Now you can use the remote operations available within the connector,
Expand Down Expand Up @@ -195,7 +212,7 @@ public function main() returns error? {
asb:Message|asb:Error? messageReceived = asbReceiver->receive(serverWaitTime);
if (messageReceived is asb:Message) {
log:printInfo("Reading Received Message : " + message received.toString());
log:printInfo("Reading Received Message : " + messageReceived.toString());
} else if (messageReceived is ()) {
log:printError("No message in the queue.");
} else {
Expand All @@ -205,7 +222,22 @@ public function main() returns error? {
check asbReceiver->close();
}
```


**Receive messages from Azure service bus using `asb:Service`**

```ballerina
service asb:Service on asbListener {
isolated remote function onMessage(asb:Message message) returns error? {
log:printInfo("Reading Received Message : " + message.toString());
}
isolated remote function onError(asb:MessageRetrievalError 'error) returns error? {
log:printError("Error occurred while receiving messages from ASB", 'error);
}
}
```

### Step 4: Run the Ballerina application

```bash
Expand Down
34 changes: 33 additions & 1 deletion ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ This can be done by providing a connection string with a queue name, topic name,
asb:MessageReceiver receiver = check new (receiverConfig);
```

#### Initialize a message listener

This can be done by providing a connection string with a queue name, topic name, or subscription path.

> Here, the Receive mode is optional. (Default: PEEKLOCK)
```ballerina
configurable string connectionString = ?;
listener asb:Listener asbListener = check new (
connectionString = connectionString,
entityConfig = {
queueName: "myQueue"
}
);
```

### Step 3: Invoke connector operation

Now you can use the remote operations available within the connector,
Expand Down Expand Up @@ -198,7 +215,22 @@ public function main() returns error? {
check queueReceiver->close();
}
```


**Receive messages from Azure service bus using `asb:Service`**

```ballerina
service asb:Service on asbListener {
isolated remote function onMessage(asb:Message message) returns error? {
log:printInfo("Reading Received Message : " + message.toString());
}
isolated remote function onError(asb:MessageRetrievalError 'error) returns error? {
log:printError("Error occurred while receiving messages from ASB", 'error);
}
}
```

### Step 4: Run the Ballerina application

```bash
Expand Down
34 changes: 33 additions & 1 deletion ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ This can be done by providing a connection string with a queue name, topic name,
asb:MessageReceiver receiver = check new (receiverConfig);
```

#### Initialize a message listener

This can be done by providing a connection string with a queue name, topic name, or subscription path.

> Here, the Receive mode is optional. (Default: PEEKLOCK)
```ballerina
configurable string connectionString = ?;
listener asb:Listener asbListener = check new (
connectionString = connectionString,
entityConfig = {
queueName: "myQueue"
}
);
```

### Step 3: Invoke connector operation

Now you can use the remote operations available within the connector,
Expand Down Expand Up @@ -198,7 +215,22 @@ public function main() returns error? {
check queueReceiver->close();
}
```


**Receive messages from Azure service bus using `asb:Service`**

```ballerina
service asb:Service on asbListener {
isolated remote function onMessage(asb:Message message) returns error? {
log:printInfo("Reading Received Message : " + message.toString());
}
isolated remote function onError(asb:MessageRetrievalError 'error) returns error? {
log:printError("Error occurred while receiving messages from ASB", 'error);
}
}
```

### Step 4: Run the Ballerina application

```bash
Expand Down

0 comments on commit d4cb689

Please sign in to comment.