Added: incubator/activemq/site/Spring+Support URL: http://svn.apache.org/viewcvs/incubator/activemq/site/Spring%2BSupport?rev=374430&view=auto ============================================================================== --- incubator/activemq/site/Spring+Support (added) +++ incubator/activemq/site/Spring+Support Thu Feb 2 08:31:10 2006 @@ -0,0 +1,304 @@ + + + + + + + + ActiveMQ - Spring Support + + + + + + + + + + + + + + + +
+ + + + + + +
+

Overview

+ +

Community

+ +

Using ActiveMQ

+ +

Features

+ +

Connectivitiy

+ +

Utilities

+ +

External Tools

+ +

Related Projects

+ +

Support

+ +

Developers

+ +

Tools we use

+ +

Feeds

+ + + + + + + + + +
+
+
+ Site +
+ + + News +
+
+ +
+ + + + + +
+ Spring Support + + +
+
+ + +
+
+

We fully support Spring for configuration of the JMS client side as well as for configuring the JMS Message Broker.

+

Configuring the JMS client

+

To configure an ActiveMQ JMS client in Spring it is just a simple matter of configuring an instance of ActiveMQConnectionFactory within a standard Spring XML configuration file like any other bean. There are several examples and test cases available and this one shows how to construct an ActiveMQConnectionFactory in Spring which is then passed into a Spring JmsTemplate for use by some POJOs.

+

e.g. the following fragment of XML shows us creating a JMS connection factory for ActiveMQ connecting to a remote broker on a specific host name and port.

+

+

+
<bean id="jmsFactory" class="org.activemq.ActiveMQConnectionFactory">
+    <property name="brokerURL">
+      <value>tcp://localhost:61616</value>
+    </property>
+  </bean>
+
+

+

The following shows how to use Zeroconf to discover the available brokers to connect to.

+

+

+
<bean id="jmsFactory" class="org.activemq.ActiveMQConnectionFactory">
+    <property name="brokerURL">
+      <value>zeroconf://_activemq.broker.development.</value>
+    </property>
+  </bean>
+
+

+

From 1.1 of ActiveMQ onwards you can also use JNDI to configure ActiveMQ within Spring. This example shows how to configure Spring using ActiveMQ's JNDI Support.

+

Working with Spring's JmsTemplate

+

Spring supports a handy abstraction, JmsTemplate, which allows you to hide some of the lower level JMS details when sending messages etc.

+

Please be aware that there are a number of JmsTemplate Gotchas to be careful of.

+

One thing to bear in mind with JmsTemplate is that by default it will create a new connection, session, producer for each message sent - then close them all down again. This is very inefficient! It is done like this to work in EJB containers which tend to use a special ConnectionFactory which does pooling.

+

We do have a pooling JMS ConnectionFactory for use inside a JCA / MDB container (org.activemq.ra.jms.ConnectionProxyFactory), when using our JCA Resource Adapter which will reuse the same JMS connection/session which is being used for inbound messages.

+

If you are not using a JCA container to manage your JMS connections, we recommend you use our pooling JMS connection provider, (org.activemq.pool.PooledConnectionFactory) which will pool the JMS resources to work efficiently with Spring's JmsTemplate or with EJBs.

+

e.g.

+

+

+
<!-- a pooling based JMS provider -->
+  <bean id="jmsFactory" class="org.activemq.pool.PooledConnectionFactory">
+    <property name="connectionFactory">
+      <bean class="org.activemq.ActiveMQConnectionFactory">
+        <property name="brokerURL">
+          <value>tcp://localhost:61616</value>
+        </property>
+      </bean>
+    </property>
+  </bean>
+
+  <!-- Spring JMS Template -->
+  <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
+    <property name="connectionFactory">
+      <ref local="jmsFactory"/>
+    </property>
+  </bean>
+
+

+

Consuming JMS from inside Spring

+

We support full message driven pojo support in Spring by using the JCA Container module. This provides all the power of MDBs - efficient JMS consumption and pooling of the message listeners - but without requiring a full EJB container.

+

Using an embedded broker

+

To create an embedded broker inside Spring its easiest to do it explicitly as follows...

+

+

+
<bean id="broker" class="org.activemq.spring.BrokerFactoryBean">
+    <property name="config" value="classpath:foo/bar/broker.xml"/>
+  </bean>
+
+

+

It is also possible to include an embedded Message Broker inside the ActiveMQConnectionFactory which is configured via our Xml Configuration mechanism, all within a normal Spring configuration file. This example demonstrates this - the trick is to specify the brokerContainerFactory property on the ActiveMQConnectionFactory which references the XML Configuration for the Broker using a Spring resource. e.g. here's an example

+

+

+
<bean id="jmsFactory" class="org.activemq.ActiveMQConnectionFactory">
+    <property name="brokerURL">
+      <value>vm://localhost</value>
+    </property>
+    <property name="useEmbeddedBroker">
+      <value>true</value>
+    </property>
+    <!-- specify that the ActiveMQ XML config file should be used to configure the Broker -->
+    <property name="brokerXmlConfig">
+      <value>org/activemq/spring/example.xml</value>
+    </property>
+  </bean>
+
+

+

We have our own Xml Configuration to configure the Message Broker which uses Spring's XML configuration mechanism. It is implemented by transforming our XML into standard Spring XML and then we use the normal Spring XML bean factory configuration mechanism. This means that we can configure any Spring components within the ActiveMQ broker XML configuration.

+
+
+ +   +