Java Reference
In-Depth Information
The methods for sending and receiving mail information are defined in the FrontDesk and
BackOffice interfaces as follows:
package com.apress.springenterpriserecipes.post;
public interface FrontDesk {
public void sendMail(Mail mail);
}
package com.apress.springenterpriserecipes.post;
public interface BackOffice {
public Mail receiveMail( );
}
Before you can send and receive JMS messages, you need to install a JMS message broker. For
simplicity's sake, I have chosen Apache ActiveMQ ( http://activemq.apache.org / ) as my message
broker, which is very easy to install and configure. ActiveMQ is an open source message broker that fully
supports JMS 1.1.
Note You can download ActiveMQ (e.g., v5.2.0) from the ActiveMQ web site and extract it to a directory of your
choice to complete the installation.
Sending and Receiving Messages Without Spring's Support
First, let's see how to send and receive JMS messages without Spring's support. The following
FrontDeskImpl class sends JMS messages with the JMS API directly.
Note To send/receive JMS messages to/from a JMS message broker, you have to include the library of the
message broker in your classpath. For ActiveMQ 5.0.0, it's activemq-all-5.0.0.jar (located in the root of
the ActiveMQ installation). Alternatively, you can use the Maven project included for this topic's source code, which
includes the ActiveMQ and JMS jars.
package com.apress.springenterpriserecipes.post;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
Search WWH ::




Custom Search