Skip to content

Commit

Permalink
Restructure MQRFH2 headers sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed Feb 26, 2024
1 parent f4f9da1 commit a063d9a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/produce-mqrfh2-headers/.github/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
org = "wso2"
name = "send_mqrfh2_headers"
name = "produce_mqrfh2_headers"
version = "0.1.0"
distribution = "2201.8.2"

Expand Down
7 changes: 7 additions & 0 deletions examples/produce-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/produce-mqrfh2-headers/Produce MQRFH2 Headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Produce MQRFH2 headers

This example demonstrates how to produce IBM MQ messages to an IBM MQ queue with MQRFH2 headers.

## 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
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand All @@ -16,11 +16,23 @@

import ballerinax/ibm.ibmmq;

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 producer = check queueManager.accessQueue("DEV.QUEUE.1", ibmmq:MQOO_OUTPUT);
ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_OUTPUT);

ibmmq:MQRFH2 mqrfh2Header = {
flags: 12,
Expand All @@ -31,10 +43,10 @@ public function main() returns error? {
]
};

check producer->put({
check queue->put({
headers: [mqrfh2Header],
payload: "This is a sample message to IBM MQ queue".toBytes()
});
check producer->close();
check queue->close();
check queueManager.disconnect();
}

0 comments on commit a063d9a

Please sign in to comment.