diff --git a/examples/produce-messages/.github/README.md b/examples/produce-messages/.github/README.md new file mode 100644 index 0000000..1325311 --- /dev/null +++ b/examples/produce-messages/.github/README.md @@ -0,0 +1 @@ +../Produce Messages.md \ No newline at end of file diff --git a/examples/produce-messages/Ballerina.toml b/examples/produce-messages/Ballerina.toml new file mode 100644 index 0000000..29348d0 --- /dev/null +++ b/examples/produce-messages/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "produce_messages" +version = "0.1.0" +distribution = "2201.8.4" + +[build-options] +observabilityIncluded = true diff --git a/examples/produce-messages/Config.toml b/examples/produce-messages/Config.toml new file mode 100644 index 0000000..aa26aaf --- /dev/null +++ b/examples/produce-messages/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-messages/Produce Messages.md b/examples/produce-messages/Produce Messages.md new file mode 100644 index 0000000..37449f9 --- /dev/null +++ b/examples/produce-messages/Produce Messages.md @@ -0,0 +1,31 @@ +# Produce messages + +This example demonstrates how to produce messages to an IBM MQ queue. + +## Prerequisites + +### 1. Setup Gmail API + +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 + +Configure Gmail API credentials 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/produce-messages/main.bal b/examples/produce-messages/main.bal new file mode 100644 index 0000000..05716bc --- /dev/null +++ b/examples/produce-messages/main.bal @@ -0,0 +1,41 @@ +// 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 +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +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 = queueManagerName, + host = host, + channel = channel, + userID = userID, + password = password + ); + ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_OUTPUT); + check queue->put({ + payload: "This is a sample message to IBM MQ queue".toBytes() + }); + check queue->close(); + check queueManager.disconnect(); +}