Module ibm.ibmmq

ballerinax/ibm.ibmmq Ballerina library
Overview
IBM MQ is a powerful messaging middleware platform designed for facilitating reliable communication between disparate systems and applications. IBM MQ ensures the secure and orderly exchange of messages asynchronously, decoupling senders and receivers for efficient and scalable communication. It supports both point-to-point and publish/subscribe messaging models via queues and topics.
The ballerinax/ibm.ibmmq
package provides an API to connect to an IBM MQ server using Ballerina. The current connector is compatible with IBM MQ server versions up to 9.3.
Setup guide
To use the Ballerina IBM MQ connector, you need to have an IBM MQ instance running or possess an IBM MQ cloud account. For setting up IBM MQ locally, you can refer to the IBM MQ official documentation. Alternatively, to use IBM MQ on the cloud, sign up for an IBM MQ cloud account.
Create a queue
-
Log into IBM MQ console. If you are running an IBM MQ server locally you can navigate to
https://<host>:<port>/ibmmq/console
URL in your browser to access the IBM MQ console. -
Click on the
Create a queue
link. -
Select the queue type.
Create a topic
-
Go back to the home page and click on the
Manage
link on the sidebar. -
Navigate to
Events
tab. -
Click on
Create
.
Quickstart
To use the IBM MQ connector in your Ballerina application, modify the .bal
file as follows:
Step 1: Import the connector
Import ballerinax/ibm.ibmmq
module into your Ballerina project.
import ballerinax/ibm.ibmmq;
Step 2: Add IBM MQ driver
Add com.ibm.mq.allclient
as a platform dependency to the Ballerina.toml
.
[[platform.java17.dependency]] groupId = "com.ibm.mq" artifactId = "com.ibm.mq.allclient" version = "9.3.4.0"
Step 3: Instantiate a new connector
Create an ibmmq:QueueManager
instance by giving IBM MQ configuration.
configurable string queueManagerName = ?; configurable string host = ?; configurable int port = ?; configurable string channel = ?; configurable string userID = ?; configurable string password = ?; ibmmq:QueueManager queueManager = check new ( name = queueManagerName, host = host, channel = channel, userID = userID, password = password );
Create an ibmmq:Queue
or ibmmq:Topic
using the ibmmq:QueueManager
instance with relevant configurations.
configurable string queueName = ?; ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_OUTPUT | ibmmq:MQOO_INPUT_AS_Q_DEF);
Create an ibmmq:Topic
using the ibmmq:QueueManager
instance with relevant configurations.
configurable string topicName = ?; configurable string topicString = ?; ibmmq:Topic topic = check queueManager.accessTopic( topicName, topicString, ibmmq:MQOO_OUTPUT | ibmmq:MQOO_INPUT_AS_Q_DEF );
Step 4: Invoke the connector operations
Now, utilize the available connector operations.
Produce messages to an IBM MQ queue
check queue->put({ payload: "This is a sample message to IBM MQ queue".toBytes() });
Produce messages to an IBM MQ topic
check topic->put({ payload: "This is a sample message to IBM MQ topic".toBytes() });
Retrieve messages from an IBM MQ queue
ibmmq:Message? message = check queue->get();
Retrieve messages from an IBM MQ topic
ibmmq:Message? message = check topic->get();
Step 5: Run the Ballerina application
bal run
Examples
The following example shows how to use the ibm.ibmmq
connector to produce and consume messages using an IBM MQ server.
-
Produce messages - Produce messages to an IBM MQ queue.
-
Consume messages - Consume messages from an IBM MQ queue.
-
Securing IBM MQ client - Initiate secure communication between an IBM MQ client and an IBM MQ server.
-
Produce MQIIH headers - Produce IBM MQ messages to an IBM MQ queue with the MQIIH headers.
-
Consume MQIIH headers - Consume messages with the MQIIH header from an IBM MQ queue.
-
Produce MQRFH2 headers - Produce IBM MQ messages to an IBM MQ queue with the MQRFH2 headers.
-
Consume MQRFH2 headers - Consume messages with the MQRFH2 header from an IBM MQ queue.