Skip to content

Commit

Permalink
Restructure MQRFH2 header consuming example
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed Feb 26, 2024
1 parent c5dc2c6 commit 37df1ac
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/consume-mqrfh2-headers/.github/README.md
7 changes: 7 additions & 0 deletions examples/consume-mqrfh2-headers/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
queueManagerName = "QM1"
host = "localhost"
port = 1414
channel = "DEV.APP.SVRCONN"
userID = "app"
password = "password"
queueName = "DEV.QUEUE.1"
31 changes: 31 additions & 0 deletions examples/consume-mqrfh2-headers/Consume MQRFH2 Headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Consume MQRFH2 headers

This example demonstrates how to consume messages with MQRFH2 header from an IBM MQ queue.

## Prerequisites

### 1. Setup IBM MQ server

Refer to the [Setup Guide](https://dev-central.ballerina.io/ballerinax/ibm.ibmmq/latest#setup-guide) to set up the IBM MQ server locally.

### 2. Configuration

Update IBM MQ related configurations in `Config.toml` in the example directory:

```toml
queueManagerName = "<queue-manager-name>"
host = "<host>"
port = <port>
channel = "<ibm-mq-channel>"
userID = "<user-ID>"
password = "<password>"
queueName = "<queue-name>"
```

## Run the Example

Execute the following command to run the example:

```bash
bal run
```
20 changes: 16 additions & 4 deletions examples/consume-mqrfh2-headers/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@
import ballerinax/ibm.ibmmq;
import ballerina/io;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;
configurable string queueName = ?;

public function main() returns error? {
ibmmq:QueueManager queueManager = check new (
name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"
name = queueManagerName,
host = host,
channel = channel,
userID = userID,
password = password
);
ibmmq:Queue consumer = check queueManager.accessQueue(
"DEV.QUEUE.1", ibmmq:MQOO_INPUT_AS_Q_DEF);
ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_INPUT_AS_Q_DEF);

while true {
ibmmq:Message? message = check consumer->get(options = ibmmq:MQGMO_WAIT);
ibmmq:Message? message = check queue->get(options = ibmmq:MQGMO_WAIT);
if message is () {
continue;
}
Expand Down

0 comments on commit 37df1ac

Please sign in to comment.