Archive

Archive for July, 2008

Spring MDP

July 1st, 2008 No comments

MDP (Message Driven Pojo) introduced in Spring 2.x offers a nice alternative to EJB’s Message Driven Beans.

package com.inflinx.test.mdp;

import javax.jms.Message;
import javax.jms.MessageListener;

public class TestMdp implements MessageListener
{
  public void onMessage(Message message)
  {
    System.out.println(message);
  }
}

Creating and configuring a MDP in Spring is a pretty straight forward process. The first step is to create a class that implements javax.jms.MessageListener interface.

Once the message listener is in place, the next step is to configure the MDP and related JMS components in Spring application context.  
<bean id=“testMdp” class=com.inflinx.test.mdp.TestMdp” />
<jee:jndi-lookup id=“connectionFactory” jndi-name=“jms.testConnectionFactory” />
<jee:jndi-lookup id=“queue” jndi-name=“jms.testQueue” />
<bean id=“jmsTransactionManager” class=“org.springframework.jms.connection.JmsTransactionManager”>
<property name=“connectionFactory” ref=“connectionFactory” />


</bean>



<bean id=“jmsContainer” class=“org.springframework.jms.listener.DefaultMessageListenerContainer”>

<property name=“connectionFactory” ref=“connectionFactory”/>

<property name=“destination” ref=“queue”/>

<property name=“messageListener” ref=“testMdp” />

<property name=“transactionManager” ref=“jmsTransactionManager” />

</bean>

Categories: Solutions Log, Spring Tags: