Now enter Spring
All we need is inject a JmsTemplate and Destination to producer/consumer bean.
Here is how to send a message in producer bean.
jmsTemplate.send(destination,
new MessageCreator()
{
public Message createMessage(Session session) throws JMSException
{
TextMessage message = session.createTextMessage("Hello, World!");
return message;
}
});
Here is how to receive a message in consumer bean.Message message = (Message) jmsTemplate.receive(destination);Here is the configuration for JmsTemplate and Destination
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616"/> </bean> <bean id="queue_destination" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg index="0" value="BolunQueue"/> </bean>You are welcome!