Java Reference
In-Depth Information
A POJO is registered to a listener container through a MessageListenerAdapter instance. This adapter
implements the MessageListener interface and will delegate message handling to the target bean's
method via reflection.
<beans ...>
<bean id="mailListener"
class="" />
<bean id="mailListenerAdapter"
<property name="delegate" ref="mailListener" />
<property name="defaultListenerMethod" value="displayMail" />
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationName" value="mail.queue" />
<property name="messageListener" ref="mailListenerAdapter" />
You have to set the delegate property of MessageListenerAdapter to your target bean. By default,
this adapter will call the method whose name is handleMessage on that bean. If you want to call another
method, you can specify it in the defaultListenerMethod property. Finally, notice that you have to
register the listener adapter, not the target bean, with the listener container.
Converting JMS Messages
You can also create a message converter for converting mail objects from JMS messages that contain mail
information. Because message listeners receive messages only, the method toMessage() will not be called,
so you can simply return null for it. However, if you use this message converter for sending messages too,
you have to implement this method. The following example reprints the MailMessageConvertor class
written earlier:
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;
public class MailMessageConverter implements MessageConverter {
Search WWH ::

Custom Search