blob: 03090b2d06acf023efc643a7969ae8cc3b135beb [file] [log] [blame]
<div class="wiki-content maincontent">
<p>Spring supports a useful JMS abstraction called JmsTemplate which makes sending and consuming messages a little simpler than using the JMS APIs directly. The only downside of this abstraction is that each send() will create a connection, session, producer, send the message, then close them all down. This is a really inefficient operation with most JMS providers as each create of a connection, session, producer ends up being an RPC with the broker, if nothing else, for security reasons.</p>
<p>In 3.1-M2 or later of ActiveMQ there's a <link><page ri:content-title="Spring Support"></page><link-body>simple solution</link-body></link> using the org.activemq.pool.PooledConnectionFactory which will perform pooling of JMS resources (connection, session, producer) to make sending messages efficiently. The same thing is true if you wanna use a similar pattern to the JmsTemplate to send messages from inside EJBs.</p>
<p>Here's an example of it in use inside a Spring config file.</p>
<structured-macro ac:macro-id="7b9bb11a-30f0-4e85-aa75-6895f8975cf1" ac:name="code" ac:schema-version="1"><plain-text-body>
&lt;!-- a pooling based JMS provider --&gt;
&lt;bean id="jmsFactory" class="org.activemq.pool.PooledConnectionFactory"&gt;
&lt;property name="connectionFactory"&gt;
&lt;bean class="org.activemq.ActiveMQConnectionFactory"&gt;
&lt;property name="brokerURL"&gt;
&lt;value&gt;tcp://localhost:61616&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;!-- Spring JMS Template --&gt;
&lt;bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
&lt;property name="connectionFactory"&gt;
&lt;ref local="jmsFactory"/&gt;
&lt;/property&gt;
&lt;/bean&gt;
</plain-text-body></structured-macro></div>