JBoss and Spring JMS
We are playing around with the JBoss application server 4.2.2GA and Spring JMS. The whole setup is very simple; assuming you want to use a JMS queue, you need to configure it in JBoss and then use the new Spring 2.5 jms namespace.
Let’s begin with the JBoss configuration. You need to drop the *-service.xml file into $SERVER_DIR/deploy/jms. The contents of the file define the destinations and queue names; the file we will show here includes two queues.
<server>
<mbean code="org.jboss.mq.server.jmx.Queue"
name="jboss.mq.destination:service=Queue,name=invoice-data">
<depends optional-attribute-name="DestinationManager">
jboss.mq:service=DestinationManager
</depends>
<depends optional-attribute-name="SecurityManager">
jboss.mq:service=SecurityManager
</depends>
<attribute name="MessageCounterHistoryDayLimit">-1</attribute>
<attribute name="SecurityConf">
<security>
<role name="guest" read="true" write="true"/>
<role name="publisher" read="true" write="true" create="false"/>
<role name="noacc" read="false" write="false" create="false"/>
</security>
</attribute>
</mbean>
Next, we define the Spring queueConnectionFactory and jmsTemplate beans, as shown in the following context file
<beans>
...
<jee:jndi-lookup jndi-name="java:ConnectionFactory"
id="queueConnectionFactory" expected-type="javax.jms.ConnectionFactory"/>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate102">
<property name="connectionFactory" ref="queueConnectionFactory"/>
</bean>
<jms:listener-container
connection-factory="queueConnectionFactory"
concurrency="10">
<jms:listener destination="invoice-data"
ref="mdb" method="mdbMethod"/>
</jms:listener-container>
...
</beans>
The mdb bean refers to a standard POJO with the mdbMethod. The signature of the mdbMethod follows pattern void mdbMehtod(argument). Now, depending on the type of the message, the argument is either the object we send in ObjectMessage or String if we send TextMessages.