<ibm-mq:consume config-ref="IBM_MQ_config" destination="#[vars.destination]"/>
To Consume IBM MQ Messages
The Consume operation in the IBM MQ connector provides the ability to consume a message at any given time of the flow, from any given Destination.
The syntax to consume a message from a queue is:
The operation above consumes the first available message in the queue identified by the destination, and then converts it to a Mule Message resulting in the following structure:
The message’s content as the payload.
The message’s metadata in the message attributes.
Once received, the message is immediately acknowledged by default. If you
want to control the ACK of the message after some processing, then set
For more information regarding a Message ACK, see Handling Message Acknowledgment.
By default, the maximum wait time is configured to 10 seconds, producing a
IBM-MQ:TIMEOUT error if no message is available in that period.
To configure a timeout that fits better your use case, customize the
To wait indefinitely for a message to arrive, the
has to be set to
-1. In this case, no TIMEOUT error is thrown.
The IBM MQ connector provides full support for filtering which messages should be consumed based on the standard JMS selector language.
For example, if you have a priority queue with messages that need to be processed faster than the others, we can do:
<ibm-mq:consume config-ref="IBM_MQ_config" destination="openTickets" selector="JMSPriority=8"/>
When a selector is configured, only the Messages matching it will be received, ignoring if any other Message is in the destination.
The IBM MQ Connector does its best to automatically determine a message’s MIME type
contentType) based on the MM_MESSAGE_CONTENT_TYPE property. However, there
are cases in which that best guess is not enough, and you need first-hand knowledge of the message’s content.
In such cases, you can force that content type to a particular value by using
The same process works for encoding. By default, the connector assumes that
the Mule runtime’s default encoding matches the one in the message if no other
information is provided. You can set this by using the
This MIME type propagation only works when the IBM MQ Target Client is selected as
Consuming messages from a topic destination is very similar to consuming them from a queue, but with the extra functionality of being able to use topic subscriptions to share state between consumers.
The syntax for consuming messages from a topic is:
<ibm-mq:consume config-ref="IBM_MQ_config" destination="#[vars.destination]"> <ibm-mq:consumer-type> <ibm-mq:topic-consumer/> </ibm-mq:consumer-type> </ibm-mq:consume>
All the consume operation parameters remain the same, but now you can handle
the subscription configuration in the
For details on how to configure the topic subscriptions see Using Topic Subscriptions.
Each received message consists of two parts:
Payload: The content of the message.
Attributes: The metadata regarding the message.
This metadata has three parts that map all the information available in a JMS message:
See JMS Reference for details regarding the attributes structure.