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.
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.
-
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.
-
Go back to the home page and click on the
Manage
link on the sidebar. -
Navigate to
Events
tab. -
Click on
Create
.
To use the IBM MQ connector in your Ballerina application, modify the .bal
file as follows:
Import ballerinax/ibm.ibmmq
module into your Ballerina project.
import ballerinax/ibm.ibmmq;
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"
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, port = port, 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
);
Now, utilize the available connector operations.
check queue->put({
payload: "This is a sample message to IBM MQ queue".toBytes()
});
check topic->put({
payload: "This is a sample message to IBM MQ topic".toBytes()
});
ibmmq:Message? message = check queue->get();
ibmmq:Message? message = check topic->get();
bal run
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 MQIIH headers - Consume messages with the MQRFH2 header from an IBM MQ queue.
Issues and Projects tabs are disabled for this repository as this is part of the Ballerina Standard Library. To report bugs, request new features, start new discussions, view project boards, etc., go to the Ballerina Standard Library parent repository.
This repository only contains the source code for the library.
-
Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations).
-
Generate a Github access token with read package permissions, then set the following
env
variables:export packageUser=<Your GitHub Username> export packagePAT=<GitHub Personal Access Token>
-
Download and install Docker. This is required to run the tests.
Execute the commands below to build from the source.
-
To build the library:
./gradlew clean build
-
To run the tests:
./gradlew clean test
-
To build the library without the tests:
./gradlew clean build -x test
-
To debug library implementation:
./gradlew clean build -Pdebug=<port>
-
To run a group of tests:
./gradlew clean test -Pgroups=<test_group_names>
-
To debug the library with Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish ZIP artifact to the local
.m2
repository:./gradlew clean build publishToMavenLocal
-
Publish the generated artifacts to the local Ballerina central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina central repository:
./gradlew clean build -PpublishToCentral=true
As an open source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All the contributors are encouraged to read the Ballerina Code of Conduct.
- For more information go to the
ibm.ibmmq
library. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.