Java Reference
In-Depth Information
public void setDestination(Destination destination) {
this.destination = destination;
}
public Mail receiveMail() {
MapMessage message = (MapMessage) jmsTemplate.receive(destination);
try {
if (message == null) {
return null;
}
Mail mail = new Mail();
mail.setMailId(message.getString("mailId"));
mail.setCountry(message.getString("country"));
mail.setWeight(message.getDouble("weight"));
return mail;
} catch (JMSException e) {
throw JmsUtils.convertJmsAccessException(e);
}
}
}
However, when extracting information from the received MapMessage object, you still have to
handle the JMS API's JMSException . This is in stark contrast to the default behavior of the framework,
where it automatically maps exceptions for you when invoking methods on the JmsTemplate . To
make the type of the exception thrown by this method consistent, you have to make a call to
JmsUtils.convertJmsAccessException() to convert the JMS API's JMSException into Spring's
JmsException .
In the back office subsystem's bean configuration file, you declare a JMS template and inject it
together with the message destination into your back office bean.
<beans ...>
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value=" tcp://localhost:61616" />
</bean>
<bean id="mailDestination"
class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="mail.queue" />
</bean>
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="receiveTimeout" value="10000" />
</bean>
Search WWH ::




Custom Search