I want to share the single instance of JMSTemplate for multiple producers connecting to ActiveMQ broker. Sample config:
<bean id="ProducerJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="gloProducerJmsFactory" />
</property>
</bean>
<bean id="pnlMessageProducer1" class="glo.business.core.FAGSCompletionMessage1"
p:jmsTemplate-ref="ProducerJmsTemplate"
p:messageDestination-ref="topic_loadGearTb1"
</bean>
<bean id="pnlMessageProducer2" class="glo.business.core.FAGSCompletionMessage2"
p:jmsTemplate-ref="ProducerJmsTemplate"
p:messageDestination-ref="topic_loadGearTb2"
</bean>
Can I use above configuration ?
As mentioned here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html
Instances of the JmsTemplate class are thread-safe once configured. This is important because it means that you can configure a single instance of a JmsTemplate and then safely inject this shared reference into multiple collaborators. To be clear, the JmsTemplate is stateful, in that it maintains a reference to a ConnectionFactory, but this state is not conversational state.
Thanks,
Anuj