Sharing a JMS session between producer and consumer from different topics using Sprin
How can I share a single session between two topics using Spring?
Without Spring it is straightforward to do
Look up ConnectionFactory using either of the two clientIds (both topics are on same broker)
Code:
Connection connection = connectionFactory.createConnection();
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
session.createdurableSubscriber(Topic A);
session.createProducer(Topic B);
so this way both the consumer for topic A and producer for topic B come under the same session.
I want to replicate this behavior using the Spring framework
What I have so far is two jmsTemplates
Code:
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory1"/>
<property name="pubSubDomain" value="true"/>
<property name="deliveryPersistent" value="true"/>
</bean>
<bean id="jmsTemplate1" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory2"/>
<property name="pubSubDomain" value="true"/>
<property name="deliveryPersistent" value="true"/>
</bean>
ConnectionFactory1 and ConnectionFactory are different in that the name used to look them up in the JNDI is different as they both have different client IDs.