---
schema_version: "1"
id: 4030791ab2b45be3379ac6ccd0ab0977b975a489a9c42fb81a1f0a043d8394b0
title: To Consume IBM MQ Messages
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/ibm-mq-connector/1.7/ibm-mq-consume.md
canonical_url: https://docs.mulesoft.com/ibm-mq-connector/1.7/ibm-mq-consume
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ece2140089a26139467533e2c39f6e26d64a44be6bed91edce7e62b5bc4b95f4
description: MuleSoft Documentation Site
release: "1.7"
latest: false
---
---
product: IBM MQ Connector
version: 1.7
keywords: jms, connector, consume, message
---

# To Consume IBM MQ Messages

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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.

## Consuming a Message

The syntax to consume a message from a queue is:

```xml
<ibm-mq:consume config-ref="IBM_MQ_config" destination="#[vars.destination]"/>
```

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 `ackMode` to `MANUAL`. For more information regarding a
Message ACK, see [Handling Message Acknowledgment](https://docs.mulesoft.com/ibm-mq-connector/1.7/ibm-mq-ack).

## Waiting for a Message

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 `maximumWait` and `maximumWaitUnit` parameters.

To wait indefinitely for a message to arrive, the `maximumWait` value has to be set to `-1`. In this
case, no TIMEOUT error is thrown.

## Filtering Incoming Messages

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:

```xml
<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.

## MIME Types and Encoding

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 `contentType`
parameter.

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 `encoding` parameter.

> [!WARNING] This MIME type propagation only works when the IBM MQ Target Client is selected as
> `JMS_COMPLIANT`.

## Consuming a Message Using Topic Subscriptions

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:

```xml
<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 `topic-consumer` parameter.

For details on how to configure the topic subscriptions see
[Using Topic Subscriptions](https://docs.mulesoft.com/ibm-mq-connector/1.7/ibm-mq-topic-subscription).

## Incoming Message Metadata

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:

- AckId

- Headers

- Properties

See [JMS Reference](https://docs.mulesoft.com/ibm-mq-connector/1.7/ibm-mq-xml-ref) for details regarding the attributes structure.

## See Also

- [Using Topic Subscriptions](https://docs.mulesoft.com/ibm-mq-connector/1.7/ibm-mq-topic-subscription)

- [To Listen For New Messages](https://docs.mulesoft.com/ibm-mq-connector/1.7/ibm-mq-listener)
