Skip to main content

Triggers

The ballerinax/ibm.ibmmq connector supports event-driven message consumption through an ibmmq:Listener. The listener connects to an IBM MQ queue manager, polls for messages on a configured queue or topic subscription, and invokes your service's onMessage callback for each message received.

Three components work together:

ComponentRole
ibmmq:ListenerConnects to an IBM MQ queue manager and polls for messages on configured queues or topic subscriptions.
ibmmq:ServiceDefines the onMessage callback invoked when a message is received.
ibmmq:CallerProvides transaction control (commit/rollback) and message acknowledgement within the service callback.
ibmmq:MessageThe message payload and metadata passed to the onMessage callback.

For action-based record operations, see the Action Reference.


Listener

The ibm.ibmmq:Listener establishes the connection and manages event subscriptions.

Configuration

The listener supports the following connection strategies:

Config TypeDescription
QueueManagerConfigurationConnection configuration for the IBM MQ queue manager. Uses the same configuration as QueueManager.

QueueManagerConfiguration fields:

FieldTypeDefaultDescription
namestringRequiredName of the IBM MQ queue manager.
hoststringRequiredHostname of the IBM MQ server.
portint1414Port number of the IBM MQ server.
channelstringRequiredServer connection channel name.
userIDstring()User ID for authentication.
passwordstring()Password for authentication.
sslCipherSuiteSslCipherSuite()SSL cipher suite for secure connections.
secureSocketSecureSocket()SSL/TLS trust store and key store configuration.

Initializing the listener

Basic listener initialization:

import ballerinax/ibm.ibmmq;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;

listener ibmmq:Listener ibmmqListener = new (
name = queueManagerName,
host = host,
port = port,
channel = channel,
userID = userID,
password = password
);

Service

An ibmmq:Service is a Ballerina service attached to an ibmmq:Listener. It is annotated with @ibmmq:ServiceConfig to specify the queue or topic to consume from, and implements the onMessage callback to process incoming messages.

Callback signatures

FunctionSignatureDescription
onMessageremote function onMessage(ibmmq:Message message) returns error?Invoked when a message is received from the configured queue or topic. Optionally accepts an ibmmq:Caller parameter for transaction control.
note

The @ibmmq:ServiceConfig annotation accepts either a QueueConfig (with queueName) or a TopicConfig (with topicName) to specify the message source.

Full usage example

import ballerina/log;
import ballerinax/ibm.ibmmq;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;

listener ibmmq:Listener ibmmqListener = new (
name = queueManagerName,
host = host,
port = port,
channel = channel,
userID = userID,
password = password
);

@ibmmq:ServiceConfig {
queueName: "DEV.QUEUE.1",
pollingInterval: 10
}
service on ibmmqListener {
remote function onMessage(ibmmq:Message message) returns error? {
log:printInfo("Received message",
payload = check string:fromBytes(message.payload)
);
}
}
note

For transactional processing, set sessionAckMode: ibmmq:SESSION_TRANSACTED in the service config and add an ibmmq:Caller parameter to the onMessage callback. Use caller->'commit() to commit or caller->'rollback() to roll back the transaction.


Supporting types

Message

FieldTypeDescription
payloadbyte[]The message body as a byte array.
propertiesmap<Property>Custom message properties as key-value pairs.
messageIdbyte[]Unique message identifier assigned by the queue manager.
correlationIdbyte[]Correlation identifier for linking related messages.
expiryintMessage lifetime (tenths of a second). -1 means unlimited.
priorityintMessage priority (0–9).
persistenceintMessage persistence (0 = not persistent, 1 = persistent).
messageTypeintMessage type (e.g., datagram, request, reply).
formatstringFormat name associated with the message data (e.g., "MQSTR").
replyToQueueNamestringName of the reply-to queue.
replyToQueueManagerNamestringName of the reply-to queue manager.
headersHeader[]Message headers (MQRFH2, MQRFH, MQCIH, or MQIIH).

QueueConfig

FieldTypeDescription
queueNamestringName of the queue to consume messages from.
sessionAckModeAcknowledgementModeSession acknowledgement mode (default: AUTO_ACKNOWLEDGE). Set to SESSION_TRANSACTED for transactional processing.
pollingIntervaldecimalInterval in seconds between polling attempts (default: 10).
receiveTimeoutdecimalMaximum time in seconds to wait for a message during each poll (default: 5).

TopicConfig

FieldTypeDescription
topicNamestringName of the topic to subscribe to.
noLocalbooleanIf true, messages published by the same connection are not delivered (default: false).
consumerTypeConsumerTypeType of consumer: DEFAULT, DURABLE, SHARED, or SHARED_DURABLE.
subscriberNamestringSubscription identifier name (required for durable subscriptions).
sessionAckModeAcknowledgementModeSession acknowledgement mode (default: AUTO_ACKNOWLEDGE).
pollingIntervaldecimalInterval in seconds between polling attempts (default: 10).
receiveTimeoutdecimalMaximum time in seconds to wait for a message during each poll (default: 5).

Caller

FieldTypeDescription
acknowledgefunctionAcknowledges the received message (remote function).
'commitfunctionCommits the current transaction (remote function).
'rollbackfunctionRolls back the current transaction (remote function).