Skip to content

Shared Topic Subscription

With JMS 1.1, a subscription on a topic is not permitted to have more than one consumer at a time. That is, if multiple JMS consumers subscribe to a JMS topic, and if a message comes to that topic, multiple copies of the message is forwarded to each consumer. There is no way of sharing messages between consumers that come to the topic.

With the shared subscription feature in JMS 2.0 you can overcome this restriction.  When shared subscription is used, a message that comes to a topic is forwarded to only one of the consumers. That is, if multiple JMS consumers subscribe to a JMS topic, consumers can share the messages that come to the topic. The advantage of shared topic subscription is that it allows to share the workload between consumers.

The ESB Profile of WSO2 Enterprise Integrator (WSO2 EI) can be configured as a shared topic listener that can connect to a shared topic subscription as a message consumer (subscriber) to share workload between other consumers of the subscription. The following diagram illustrates this sample scenario:

To demonstrate the sample scenario, let's configure the JMS inbound endpoint in WSO2 Micro Integrator as a shared topic listener using HornetQ as the message broker.

Synapse configuration

The XML configuration for this sample scenario is as follows:

<inboundEndpoint name="jms_inbound" sequence="request"onError="fault" protocol="jms" suspend="false">
    <parameter name="interval">1000</parameter>
    <parameter name="transport.jms.Destination">/topic/exampleTopic</parameter>
    <parameter name="transport.jms.CacheLevel">3</parameter>
    <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter>
    <parameter name="sequential">true</parameter>
    <parameter name="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</parameter>
    <parameter name="java.naming.provider.url">jnp://localhost:1099</parameter>
    <parameter name="transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter>
    <parameter name="transport.jms.SessionTransacted">false</parameter>
    <parameter name="transport.jms.ConnectionFactoryType">topic</parameter>
    <parameter name="transport.jms.JMSSpecVersion">2.0</parameter>
    <parameter name="transport.jms.SharedSubscription">true</parameter>
    <parameter name="transport.jms.DurableSubscriberName">mySubscription</parameter>
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
  <parameter name="cachableDuration">15000</parameter>
<taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager">
  <parameter name="cachableDuration">15000</parameter>
<sequence name="request" onError="fault">
  <log level="full"/>
<sequence name="fault">
  <log level="full">
    <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>
    <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
    <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>

See the descriptions of the above configurations:

Artifact Description
Inbound Endpoint Make sure to configure the below properties as follows when setting up the inbound endpoint:
  • Set the value of the transport.jms.JMSSpecVersion property as 2.0.
  • Set the value of the transport.jms.SharedSubscription propoerty as true.
  • Specify a subscriber name as the value of the transport.jms.DurableSubscriberName property and use the same for all subscribers.
Task Manager The task manager configuration...
Registry Arfiact The registry artifact..