---
schema_version: "1"
id: d6d36739b3c477c7a27758db74c9c3071f42e67e9236ee79d5f4974fab8d21b6
title: To Consume JMS Messages
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/jms-connector/1.2/jms-consume.md
canonical_url: https://docs.mulesoft.com/jms-connector/1.2/jms-consume
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 40d7145842b6a22e758547b94d23d6d70cbaec2474eef864ac45181b8b814b04
description: MuleSoft Documentation Site
release: "1.2"
latest: false
---
---
product: JMS Connector
version: 1.2
keywords: jms, connector, consume, message
---

# To Consume JMS Messages

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

The Consume operation in the JMS connector provides 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
<jms:consume config-ref="JMS_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 `MuleMessage` resulting in the following structure:

- The message’s content as payload.

- The message’s metadata in the message attributes.

Once received, the Message will be immediately ACKed by default. If you want to control the ACK of
the Message after some processing, then `ackMode` should be set to `MANUAL` For more information
regarding a Message ACK, check the [How To Handle Message Acknowledgement](https://docs.mulesoft.com/jms-connector/1.2/jms-ack).

## Waiting for a Message

By default, the maximum wait time is configured in 10 seconds, producing a `JMS:TIMEOUT` error if no
message is available in that period. If order to configure a timeout that fits better your use case,
customize the `maximumWait` and `maximumWaitUnit` parameters.

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

## Polling for a Message

When polling for a Message with a certain frequency, you don’t want the consumer to block waiting
for the Message, but instead just try to consume it if one is present. In this cases, the
`maximumWait` can be set to `0`, indicating that no waiting should occur, and neither a
`JMS:TIMEOUT` should be thrown if no Message is available in the destination. The output of the
`consume` operation will be `null` when no Message is present for consumption and no error is
thrown.

## Filtering Incoming messages

The JMS 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
<jms:consume config-ref="JMS_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 JMS Connector does its best to auto 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 will assume that the 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.

## 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
<jms:consume config-ref="JMS_config" destination="#[vars.destination]">
    <jms:consumer-type>
        <jms:topic-consumer/>
    </jms:consumer-type>
</jms: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 go to
[Using Topic Subscriptions](https://docs.mulesoft.com/jms-connector/1.2/jms-topic-subscription).

## Incoming Message Metadata

As stated before, each Message received will consist of two parts:

- The payload, containing the content of the Message

- The attributes, containing metadata regarding the Message

This Metadata has three parts that map all the information available in a JMS Message:

- AckId

- Headers

- Properties

## See Also

- [Using Topic Subscriptions](https://docs.mulesoft.com/jms-connector/1.2/jms-topic-subscription)

- [To Listen For New Messages](https://docs.mulesoft.com/jms-connector/1.2/jms-listener)
