Java Reference
In-Depth Information
On the Topic of Topics…
In this chapter, we'll refer quite a bit to topics and queues . Messaging solutions are designed to solve two
types of architecture requirements: messaging from one point in an application to another known point,
and messaging from one point in an application to many other unknown points. These patterns are the
middleware equivalents of telling somebody something face to face and saying something over a loud
speaker to a room of people, respectively.
If you want messages sent on a message queue to be broadcast to an unknown set of clients who are
“listening” for the message (as in the loud speaker analogy), send the message on a topic. If you want the
message sent to a single, known client, then you send it over a queue .
Spring offers a template-based solution for simplifying your JMS code. With a JMS template (Spring
framework class JmsTemplate ), you can send and receive JMS messages with much less code. The
template handles the boilerplate tasks for you and also converts the JMS API's JMSException hierarchy
into Spring's runtime exception org.springframework.jms.JmsException hierarchy. The translation
converts exceptions to a mirrored hierarchy of unchecked exceptions.
In JMS 1.0.2, topics and queues are known as domains and are handled with a different API that is
provided for legacy reasons, so you'll find jars or implementations of the JMS API in different application
servers: one for 1.1, and one for 1.0.2. In Spring 3.0, this 1.0.2 support in Spring is considered deprecated.
JMS 1.1 provides a domain-independent API, treating topic and queue as alternative message
destinations. To address different JMS APIs, Spring provides two JMS template classes, JmsTemplate and
JmsTemplate102 , for these two versions of JMS. This chapter will focus on JMS 1.1, which is available for
Java EE 1.4 and higher versions.
How It Works
Suppose that you are developing a post office system that includes two subsystems: the front desk
subsystem and the back office subsystem. When the front desk receives mail from a citizen, it passes
the mail to the back office for categorizing and delivering. At the same time, the front desk subsystem
sends a JMS message to the back office subsystem, notifying it of new mail. The mail information is
represented by the following class:
public class Mail {
private String mailId;
private String country;
private double weight;
// Constructors, Getters and Setters
Search WWH ::

Custom Search