Using connection pooling with JMSTemplate in Spring Framework
search cancel

Using connection pooling with JMSTemplate in Spring Framework

book

Article ID: 338928

calendar_today

Updated On:

Products

VMware

Issue/Introduction

This article provides information on using connection pooling with JMSTemplate in Spring Framework. You may want to use connection pooling if you experience a long turnaround time for every JMS message sent.


Environment

Spring Framework 3.1
Spring Framework 3.0
Spring Framework 2.5

Resolution

Without connection pooling, JMSTemplate, by default, creates a new connection, session, producer for each message sent and then closes them all again. This results in a long workaround time and you get get reconnected on every JMS message sent.
Connection pooling pools the JMS resources to work efficiently with Spring's JMSTemplate, so that it reuses connections. There are several connection pools available for use in Spring Framework, including SingleConnectionFactory, CachingConnectionPooling and the provider-specific connection Pooling ActiveMQ's PooledConnectionFactory.

Sample configuration of JMS with ActiveMQ Connection Pooling

<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://broker1:61616< /value>
</property>
</bean>
</property>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" >
< property name="connectionFactory" ref="connectionFactory"/>
</bean>