Java Reference
In-Depth Information
In the front desk subsystem's bean configuration file, you declare a JMS template that refers to the
JMS connection factory for opening connections. Then you inject this template as well as the message
destination into your front desk 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" />
</bean>
<bean id="frontDesk"
class="com.apress.springenterpriserecipes.post.FrontDeskImpl">
<property name="destination" ref="mailDestination" />
<property name="jmsTemplate" ref="jmsTemplate" />
</bean>
</beans>
To receive a JMS message with a JMS template, you call the receive() method by providing a
message destination. This method returns a JMS message whose type is the base JMS message type,
an interface, javax.jms.Message , so you have to cast it into proper type before further processing.
package com.apress.springenterpriserecipes.post;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.JmsUtils;
public class BackOfficeImpl implements BackOffice {
private JmsTemplate jmsTemplate;
private Destination destination;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
Search WWH ::




Custom Search