1. JMS Basic concepts
JMS (Java Message Service) or Java Message Service. It provides a standard production, sending and receiving messages interface simplifies enterprise application development. It supports two messaging models: point to point (point-to-point) (P2P) model and the publish / subscribe (Pub / Sub) model. P2P model provides for a message can only have one receiver; Pub / Sub model allows a message can have multiple recipients.
For point to point model, the message producer creates a message, send this message to a Queue (queue), then the message receiver and then read from the Queue, if the message read by a receiver after its disappeared in the Queue, so a message can only be a recipient of consumption.
Point to point model with different publish / subscribe model, the message producer creates a message, send this message to a Topic in the Topic can have multiple receivers in the listener, when a message arrives after the Topic, All messages will receive the message recipient.
|Simply speaking, point to point model and the publish / subscribe model is one to one difference is that the former, the latter is one to many.|
2. Several important concepts
Destination: the destination of messages, that is to say in front of Queue and Topic. After a message is created, just need to send this message to the destination, the message the sender can continue to do my own thing, without waiting for messages to be processed. As for the news when and which consumer spending will be depends entirely on the recipient of the message.
Message: literally can see the message was sent. It has the following types:
StreamMessage: Java data flow information, using standard stream operations to fill the order and read.
MapMessage: Map type a message; name string, while the value of Java's basic types.
TextMessage: ordinary string message that contains a String.
ObjectMessage: object message that contains a serializable Java object
BytesMessage: binary array of message contains a byte .
XMLMessage: an XML message types.
The most common is the TextMessage and ObjectMessage.
Session: created with the JMS provider's session, through the Session we can create a Message.
Connection: with the JMS provider to establish a connection. You can create a session from the connection, the Session.
ConnectionFactory: How to Create a Connection that it? This requires a ConnectionFactory mentioned below. With this factory class to get a connection with the JMS provider that Conection.
Producer: news producers, to send a message to be sent by the producers.
MessageConsumer: correspond with the producers, this is the message of the consumer or recipient, to receive a message through it.
JMS provider mentioned several times before, because JMS provides us with only a series of interfaces, when we use an JMS-time, or need a third party provider, and its role is to really manage the Connection, Session, Topic, and Queue and so on.
ConnectionFactory---->Connection--->Session--->Message Destination + Session------------------------------------>Producer Destination + Session------------------------------------>MessageConsumer
can be seen by following the above diagram the relationship between these concepts.
Some may then ask: ConnectionFactory and Destination from where to get?
This and related to the JMS provider. If in a JavaEE environment, you can get through the JNDI lookup, if a non-JavaEE environment, it would only provider through the JMS interface to get to us.