Working with JMS

In this example, you'll learn how to communicate asynchronously with JMS. You'll send a new reservation to the billing system, so that the system can bill the customer. We'll focus on billing (the producer side of the equation), but Spring 1.2 intends to support a robust, pooled, and transactional message consumer architecture as well.

Many architects have hailed JMS as one of the best J2EE specifications. It provides a clean separation between the specification interface and pluggable implementations. It provides for a variety of payload structures, and distinct messaging models for peer-to-peer communication and publish-subscribe style communication. In this section, you're going to integrate JMS with Spring.

How do I do that?

The first job is to configure JMS. To do so, you'll need a JMS provider. We chose ActiveMQ (http://activemq.codehaus.org) because it is open source and its authors have provided excellent Spring support, but other implementations should work as well. Download the application, and then launch the JMS provider by navigating to the /bin folder and issuing the activemq command.

In the context, you'll need to configure a connection factory to manage the JMS connection, as in Example 8-9.

Example 8-9. RentABike-servlet.xml

<bean id="jmsConnFactory" class="org.codehaus.activemq.ActiveMQConnectionFactory">
   <property name="brokerURL">
      <value>vm://localhost</value>
   </property>
</bean>

Next, you'll need a JMS transaction manager, which plugs into the Spring ...

Get Spring: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.