1 Introduction
In today's society, the information is everywhere. Most of their carriers are different systems. How do you interact with information between these systems? The answer is MOM (Message-Oriented MiddleWare). MOM allows two or more enterprise applications to interact with messages in the form of messages. Different MOM vendors provide different APIs to accept and send messages to developers, define different network protocols, management tools, etc. In order to unify these related content, Sun proposes a JMS (Java Message Service) specification. JMS is similar to JDBC, allowing application developers to reuse the same API to access different systems. The entity that implements the JMS specification (http://java.sun.com/products/jms/docs.html) is called JMS Provider, which is the bridge between the message interaction. In the JMS specification, JMS Client is divided into message sender (producers) and message recipients (consumers).
Fig1. JMS system diagram
2. JMS message composition
Fig2. JMS message composition
As can be seen from the above figure, JMS defines the following three components.
A. Header: Includes Metadata information such as Destination (Topic, or Queue) such as the Destination (Topic, or Queue) that is effective and how long the message is created, when creating, how long is the message. Each header information has a set and get interface. See the following code
public interface Message {public Destination getJMSDestination () throws JMSException; public void setJMSDestination (Destination destination) throws JMSException; public int getJMSDeliveryMode () throws JMSException; public void setJMSDeliveryMode (int deliveryMode) throws JMSException; public String getJMSMessageID () throws JMSException; public void SetjmsMsSageId (String ID) throws jmsexception; public long getjmstimestamp () throws jmsexception; public void setjmstimestamp (long timestamp) throws jmsexception;
.........
}
Some Header information is automatically set by JMS Provider, that is, the value of the developer calls the SET method will be overwritten by JMS Provider. For example, JMSDestination (Topic Or Queue), JMSDELRIVERYMODE (Persistent or NonPersistent), etc. Other JMSReplyto, JMSTYPE, etc. HEADER information is set by the developer.
B. Properties: Properties effect Similar to some additional header information. The value of Property can be Boolean, Byte, Short, Int, Long, Float, Double, or String. The JMS interface also defines these types of Property GET and SET methods. Properties is divided into three categories:
1. Application related Property, such as UserName in the following code segment Property,
TextMessage Message = PubSession.createTextMessage ();
Message.setText (Text);
Message.setStringProperty ("UserName", UserName; Publisher.Publish;
UserName is meaningless in other applications.
2. JMS defined Property, these Property and 1 of the Property have the same characteristics, but they are set by JMS Provider, actually an optional header. Provider can arbitrarily select the following Property support, or one is not supported.
· JMSXUSERID
· JMSxAppid
· JMSXProducertxid
· JMSXCONSUMERTXID
· JMSXRCVTimeStamp
· JMSxDeliveryCount
· JMSxState
· JMSxGroupID
· JMSxGroupseq
3. Provider-related Property, each JMS Provider can define a series of private Property, set by the client or provider yourself, each JMS Provider-related Property starts with JMS_, followed by Property name.
At the same time, the Provider can define the message filtering function according to the message of the message, the message filtering, reaches the message filtering. For example, the selector (black body part) is used to tell the message server only sending a message that does not contain the username this property equal to WILLIAM.
TopicsUbscriber Subscriber =
Session.createSubscriber (Chattopic, "UserName! = 'William'", FALSE);
The message selector is based on the WHERE clause in SQL.
C. PayLoad: is the real data containing the message. JMS defines five message type interface TextMessage,
StreamMessage, MapMessage, ObjectMessage, And Bytesmessage, they all inherit this Interface in Message. TextMessage uses a string as a message; ObjectMessage uses a sequentially-used object as a message for the message; bytesMessage uses the Byte array as a message; streamMessage uses the original data type of stream as a message for message; mapMessage uses Name-Value The following code explains how to set text message and send this message, other types of messages Similar:
TextMessage TextMessage = session.createtextMessage ();
TextMessage.Settext ("Hello!");
TopicPublisher.publish (TextMessage);
...
TextMessage TextMessage = session.createtextMessage ("Hello!");
Queuesender.send (TextMessage);