Java Reference
In-Depth Information
public Object fromMessage(Message message) throws JMSException,
MessageConversionException {
MapMessage mapMessage = (MapMessage) message;
Mail mail = new Mail();
mail.setMailId(mapMessage.getString("mailId"));
mail.setCountry(mapMessage.getString("country"));
mail.setWeight(mapMessage.getDouble("weight"));
return mail;
}
public Message toMessage(Object object, Session session) throws JMSException,
MessageConversionException {
...
}
}
A message converter should be applied to a listener adapter for it to convert messages into objects
before calling your POJO's methods.
<beans ...>
...
<bean id="mailMessageConverter"
class="com.apress.springenterpriserecipes.post.MailMessageConverter" />
<bean id="mailListenerAdapter"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<property name="delegate" ref="mailListener" />
<property name="defaultListenerMethod" value="displayMail" />
<property name="messageConverter" ref="mailMessageConverter" />
</bean>
</beans>
With this message converter, the listener method of your POJO can accept a mail object as the
method argument.
package com.apress.springenterpriserecipes.post;
public class MailListener {
public void displayMail(Mail mail) {
System.out.println("Mail #" + mail.getMailId() + " received");
}
}
Search WWH ::




Custom Search