The JMS specification defines the durable subscription. Basically, it is used when a subscriber needs to receive all the messages published to a topic, even those which are sent while the subscriber is off-line. Here is a quote from JMS 2.0 specification:
"A durable subscription is used by an application that needs to receive all the messages published on a topic, including the ones published when there is no consumer associated with it. The JMS provider retains a record of this durable subscription and ensures that all messages from the topic's publishers are retained until they are delivered to, and acknowledged by, a consumer on the durable subscription or until they have expired."
Durable subscription is often used for the Notification message exchange pattern. For more information about the Notification message exchange pattern, see Notification.
To connect to an ActiveMQ topic in a durable way, an additional parameter called durableSubscriptionName has to be specified in the connection URI. However, there is a limitation that from the side of one client, only one subscriber can be connected simultaneously to a given topic using a given durable subscription name. For example:
The JMS specification prohibits two or more subscribers using the same durableSubscriptionName and durableSubscriptionClientId to be connected to the same topic simultaneously. When using one WSDL for creation, for example provider and consumer (or multiple consumers), which is a usual situation, this becomes a problem, because the same JMS connection URI is shared among multiple participants. This means that if durableSubscriptionName or durableSubscriptionClientId is specified in the URI in the WSDL, all the participants will use the same parameters and only one of the participants will be allowed to connect to the topic by a message broker.
To manage this situation, a special Talend ESB feature called DurableSubscriptionFeature has been created. The feature is part of the transport-jms library, so no other dependencies are needed. The feature allows to specify durableSubscriptionName and durableSubscriptionClientId parameters individually for a participant. Here is an example of how to configure it in Spring configuration:
<bean id="subscriberDurableSubscriptionFeature" class="org.talend.esb.transport.jms.DurableSubscriptionFeature"> <property name="durableSubscriptionClientId" value="someClientId"/> <property name="durableSubscriptionName" value="someSubscriptionName"/> </bean> <jaxws:endpoint xmlns:library="http://services.talend.org/demos/Library/1.0" id="LibraryNotificationReceiver" address="jms:jndi-topic:dynamicTopics/newBooksTopic.topic?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory& ;jndiConnectionFactoryName=ConnectionFactory&jndiURL=tcp://localhost:61616&durableSubscriptionName=someAnotherName" serviceName="library:LibraryProvider" endpointName="library:LibraryTopicPort" implementor="org.talend.services.demos.client.LibraryNotificationReceiverImpl"> <jaxws:features> <ref bean="subscriberDurableSubscriptionFeature"/> </jaxws:features> </jaxws:endpoint>
Note that to make DurableSubscriptionFeature work, the durableSubscriptionName parameter should be specified in the URI. The value of the parameter will be replaced with the one provided by the feature.
With the Talend ESB Nojndi wrapper as InitialContextFactory, durable subscription in Websphere MQ is configured in the same way as described for ActiveMQ in the previous section. See below a sample JMS URI for Websphere MQ topic access with durable subscription:
jms:topic:test.durable.topic?jndiInitialContextFactory=org.talend.esb.jms.wmq.Nojndi&jndiConnectionFactoryName= connectQueueManager(QMGR)binding(client)clientChannel(EXAMPE.CHANNEL.SVRCONN)clientC onnection(localhost:1414)&jndiURL=wmq://topic&jndi-destination-type=topic&durableSubscriptionName=myDura bleSubscription