The JMS Facade
The JMS Facade attempts to merge the publish/subscribe and point-to-point message models into one interface, hiding the model itself from the programmer. In my experience, application code written around the publish/subscribe model is very similar to that written around the point-to-point model. The difference lies in the details of how each delivers the messages themselves. This difference can be considered an implementation detail and, hence, should be hidden from developers in most cases. (For an overview of the JMS message models, read the sidebar, "The Java Message Service (JMS)
To use the JMS Facade, start by importing the
com.JMSFacade package. Next, create an instance of the
com.JMSFacade.JMSManager class, as shown in Listing 4.
JMSManager does all the work.
Listing 1. The |
This is an example of importing and creating the JMS Facade class,
public class myClass
JMSManager jmsMgr = new JMSManager();
The JMS Facade attempts to abstract the concepts of publish/subscribe (Topic) and point-to-point (Queue) using the term "subject." Very simply, code written around the JMS Facade listens to, or sends messages to, a subject that is nothing more than a text name. It is not required to denote whether the destination is a topic or queue at this pointor ever.
You don't need to create subjects explicitly, even though the JMS Facade does allow it. The Facade creates subjects automatically when you call the
send methods. The only reason to explicitly create a subject is to control the message-delivery model, publish/subscribe or point-to-point. The default model is publish/subscribe.
To specify the message-delivery model, your code must call the A unique subject name in the form of a
createSubject method on the
JMSManager class. This method requires two parameters:
A subject type (the message-delivery model), which is either
A subject type specified as
BROADCAST_TYPE is equivalent to a JMS
Topic, which is the publish/subscribe model. A subject type of
SEND_ONCE_SUBJECT is equivalent to a JMS
Queue, which is the point-to-point model.