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:
-
In Studio, select the Consume operation from your flow.
-
Set the Destination field to
#[vars.destination]
. -
Set the Consumer type field to Topic consumer.
-
Select the Durable option.
-
Set the Subscription name to
SampleSub
.
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:
-
In Studio, select the Consume operation from your flow.
-
Set the Destination field to
InvoiceEventsTopic
. -
Set the Consumer type field to Topic consumer:
-
Select the Shared option.
-
Set the Subscription name to
ClusterSubscription
.
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 :
-
In Studio, select the Consume operation from your flow.
-
Set the Destination field to
{notificationsChannel}
. -
Set the Consumer type field to Topic consumer:
-
Select the No local option.
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>