Understanding of the JMS (a): JSM basis (turn)

2010-10-19  来源:本站原创  分类:Java  人气:181 

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.

相关文章
  • Understanding of the JMS (a): JSM basis (turn) 2010-10-19

    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 (poi

  • Understanding of the JMS (VII): DeliveryMode example (turn) 2010-10-19

    In the example below, respectively, Persistent and nonpersistent send a message, and then Close to exit the JMS. import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Se

  • Understanding of the JMS (II): a JMS example (turn) 2010-10-19

    A brief introduction before a bit about the basic concepts of JMS, this lecture with an example for our in-depth understanding of the basic concepts of the previous speakers. First of all need to do is to select a JMS provider, if the JavaEE environm

  • Understanding of the JMS (1) 2010-03-29

    1. JMS basic concepts of JMS (Java Message Service) or Java Message Service. It provides a standard production, sending and receiving messages interface to simplify enterprise application development. It supports two messaging models: point to point

  • Understanding of the JMS (2) an example 2010-09-07

    Speaking before a brief introduction to the basic concept of what JMS, combined with an example of this talk to our in-depth understanding of the basic concepts of the previous talk. First of all need to do is select a JMS provider, if the JavaEE env

  • Understanding of the JMS (3): real Queue 2010-03-29

    Queue implementation is to-point model, in the following example, start two consumers share monitor a Queue, and then loop to send multiple messages in the Queue, we are still using ActiveMQ. import javax.jms.Connection; import javax.jms.DeliveryMode

  • Understanding of the JMS (4): real Topic 2010-03-29

    Queue The difference is that with, Topic realize that the publish / subscribe model, in the following example, two consumers together to start listening a Topic, and then loop to send multiple messages in this Topic. import javax.jms.Connection; impo

  • Understanding of the JMS (5): message header 2010-03-29

    A message object is divided into three parts: the message headers (Headers), properties (Properties) and the message body (Payload). For StreamMessage and MapMessage, the message itself has a particular structure, but for the TextMessage, ObjectMessa

  • Understanding of the JMS (6): DeliveryMode Example 2010-03-29

    In the example below, respectively Persistent and nonpersistent send a message, and then close out of JMS. import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session;

  • Understanding of the JMS (7): JMSReplyTo 2010-03-29

    In the following example, first create two Queue, send the person to a Queue to send, the recipient receives the message to another Queue reply after a Message, and then create a consumer to accept the reply message. import javax.jms.Connection; impo

  • Understanding of the JMS (d) of the actual queue 2010-09-07

    Queue implementation is point to point model, in the following example, start two consumers to monitor a Queue, then loop to send multiple messages in the Queue, we still use ActiveMQ. import javax.jms.Connection; import javax.jms.DeliveryMode; impor

  • Understanding of the JMS (5) combat Topic 2010-09-07

    The difference is that with the Queue, Topic realize the publish / subscribe model, in the following example, start two consumers to monitor a Topic, then loop to send multiple messages to this Topic. import javax.jms.Connection; import javax.jms.JMS

  • Understanding of the JMS (6) header 2010-09-07

    A message object is divided into three parts: the message header (Headers), properties (Properties) and the message body (Payload). For StreamMessage and MapMessage, news itself has a particular structure, but for the TextMessage, ObjectMessage and B

  • Understanding of the JMS (7) DeliveryMode example 2010-09-07

    In the following example, were to send a Persistent and nonpersistent messages, and then close out of JMS. import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session;

  • Understanding of the JMS (8) JMSReplyTo 2010-09-07

    In the following example, first create two Queue, Queue to send to a sender, receiver, after receiving the message back to another Queue a Message, and then create a consumer to receive the reply message. import javax.jms.Connection; import javax.jms

  • Understanding of the JMS (9) Selector 2010-09-07

    The previous example to create a message consumer is: sesssion. createConsumer (destination) In addition, it also provides another way: sesssion. createConsumer (destination, selector) Here selector is a string used to filter messages. In other words

  • Understanding of the JMS (10) JMSCorrelationID and Selector 2010-09-07

    Have said before is mainly used to associate multiple JMSCorrelationID Message, for example, need to respond to a message when the message is usually to restore the original message JMSCorrelationID set ID. In the following example, create three news

  • Understanding of the JMS (11) TemporaryQueue and TemporaryTopic 2010-09-07

    TemporaryQueue and TemporaryTopic, literally can see that they are "temporary" destination. By Session to create, for example: TemporaryQueue replyQueue = session.createTemporaryQueue (); Although they are created by the Session, but indeed the

  • Understanding of the JMS (12) MDB 2010-09-07

    In EJB3, a MDB (Message Driven Bean) is an implementation of the MessageListener interface POJO. Here is a simple MDB. @ MessageDriven (activationConfig = ( @ ActivationConfigProperty (propertyName = "destinationType", propertyValue = "java

  • Understanding of the JMS (IV): combat Queue (rpm) 2010-10-19

    Queue implementation is the point to point model, in the following example, two consumers to start listening to a Queue, and then loop to send multiple messages in the Queue, we are still using ActiveMQ import javax.jms.Connection; import javax.jms.D