From a063d9a32d2d7fd7b6716b38284ad95f151c0787 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Mon, 26 Feb 2024 11:47:11 +0530 Subject: [PATCH] Restructure MQRFH2 headers sample --- .../produce-mqrfh2-headers/.github/README.md | 1 + .../Ballerina.toml | 2 +- examples/produce-mqrfh2-headers/Config.toml | 7 +++++ .../Produce MQRFH2 Headers.md | 31 +++++++++++++++++++ .../main.bal | 22 ++++++++++--- 5 files changed, 57 insertions(+), 6 deletions(-) create mode 120000 examples/produce-mqrfh2-headers/.github/README.md rename examples/{send-mqrfh2-headers => produce-mqrfh2-headers}/Ballerina.toml (77%) create mode 100644 examples/produce-mqrfh2-headers/Config.toml create mode 100644 examples/produce-mqrfh2-headers/Produce MQRFH2 Headers.md rename examples/{send-mqrfh2-headers => produce-mqrfh2-headers}/main.bal (67%) diff --git a/examples/produce-mqrfh2-headers/.github/README.md b/examples/produce-mqrfh2-headers/.github/README.md new file mode 120000 index 0000000..143e08e --- /dev/null +++ b/examples/produce-mqrfh2-headers/.github/README.md @@ -0,0 +1 @@ +../Produce MQRFH2 Headers.md \ No newline at end of file diff --git a/examples/send-mqrfh2-headers/Ballerina.toml b/examples/produce-mqrfh2-headers/Ballerina.toml similarity index 77% rename from examples/send-mqrfh2-headers/Ballerina.toml rename to examples/produce-mqrfh2-headers/Ballerina.toml index 29dfcb0..232cdd6 100644 --- a/examples/send-mqrfh2-headers/Ballerina.toml +++ b/examples/produce-mqrfh2-headers/Ballerina.toml @@ -1,6 +1,6 @@ [package] org = "wso2" -name = "send_mqrfh2_headers" +name = "produce_mqrfh2_headers" version = "0.1.0" distribution = "2201.8.2" diff --git a/examples/produce-mqrfh2-headers/Config.toml b/examples/produce-mqrfh2-headers/Config.toml new file mode 100644 index 0000000..aa26aaf --- /dev/null +++ b/examples/produce-mqrfh2-headers/Config.toml @@ -0,0 +1,7 @@ +queueManagerName = "QM1" +host = "localhost" +port = 1414 +channel = "DEV.APP.SVRCONN" +userID = "app" +password = "password" +queueName = "DEV.QUEUE.1" diff --git a/examples/produce-mqrfh2-headers/Produce MQRFH2 Headers.md b/examples/produce-mqrfh2-headers/Produce MQRFH2 Headers.md new file mode 100644 index 0000000..529845b --- /dev/null +++ b/examples/produce-mqrfh2-headers/Produce MQRFH2 Headers.md @@ -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 = "" +host = "" +port = +channel = "" +userID = "" +password = "" +queueName = "" +``` + +## Run the Example + +Execute the following command to run the example: + +```bash +bal run +``` diff --git a/examples/send-mqrfh2-headers/main.bal b/examples/produce-mqrfh2-headers/main.bal similarity index 67% rename from examples/send-mqrfh2-headers/main.bal rename to examples/produce-mqrfh2-headers/main.bal index fee0e02..507078f 100644 --- a/examples/send-mqrfh2-headers/main.bal +++ b/examples/produce-mqrfh2-headers/main.bal @@ -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 @@ -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, @@ -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(); }