Configure Topic Subscriptions with JMS Connector

Topic subscriptions in JMS enable you to configure how the subscription behaves regarding the connection of consumers and how consumers interact.

The Anypoint Connector for JMS (JMS Connector) Consumer and On New Message operations manage topic subscriptions in the Consumer type field by selecting the Topic consumer configuration.

Configure Durable Subscriptions

Durable subscriptions enable you to receive messages published to the topic while the consumer is offline. The JMS provider stores messages sent or published to a topic, just as it would store messages sent to a queue. If another application has a Topic consumer configuration that uses the same connection, client ID, topic, and subscription name, the subscription reactivates, and the JMS provider delivers the published messages while the subscriber was inactive.

In the following example, you Topic consumer to Durable:

  1. In Studio, select the Consume operation from your flow.

  2. Set the Destination field to #[vars.destination].

  3. Set the Consumer type field to Topic consumer.

  4. Select the Durable option.

  5. Set the Subscription name to SampleSub.

In the Consume operation screen
Figure 1. JMS Connector Topic Consumer Durable configuration

In the XML editor, the <jms:topic-consumer> and durable configurations look like this:

<jms:consume config-ref="JMS_config" destination="#[vars.destination]">
    <jms:consumer-type>
        <jms:topic-consumer durable="true" subscriptionName="SampleSub"/>
    </jms:consumer-type>
</jms:consume>

Configure Shared Subscriptions

In a JMS spec 1.1 connection, a subscription to a topic cannot have more than one consumer at a time, meaning that the processing work of messages on a topic subscription cannot be shared, thereby limiting the scalability of the application. The JMS spec 2.0 connection removes this restriction and enables you to configure shared consumers on the same subscription.

In the following example, you set Topic consumer to Shared:

  1. In Studio, select the Consume operation from your flow.

  2. Set the Destination field to InvoiceEventsTopic.

  3. Set the Consumer type field to Topic consumer:

  4. Select the Shared option.

  5. Set the Subscription name to ClusterSubscription.

In the Consume operation screen
Figure 2. JMS Connector Topic Consumer Shared configuration

In the XML editor, the <jms:topic-consumer> and shared configurations look like this:

<jms:listener config-ref="config" destination="InvoiceEventsTopic">
    <jms:consumer-type>
        <jms:topic-consumer shared="true" subscriptionName="ClusterSubscription"/>
    </jms:consumer-type>
</jms:listener>

Configure No Local Subscriptions

There are cases in which you may not want to receive published messages to a topic by the same application. To prevent the consumer to receive published messages to a topic by the same connection, configure the Topic consumer field to No local. Consumers configured as no local can not be part of a shared subscription.

In the following example, you set Topic consumer to No local :

  1. In Studio, select the Consume operation from your flow.

  2. Set the Destination field to {notificationsChannel}.

  3. Set the Consumer type field to Topic consumer:

  4. Select the No local option.

In the Consume operation screen
Figure 3. JMS Connector Topic Consumer No local configuration

In the XML editor, the <jms:topic-consumer> and noLocal configurations look like this:

<jms:listener config-ref="config" destination="${notificationsChannel}">
    <jms:consumer-type>
        <jms:topic-consumer noLocal="true"/>
    </jms:consumer-type>
</jms:listener>