Getting started with JMS (1)-Basic JMS

Source: Internet
Author: User

1. Basic concepts of JMS

Java Message Service (JMS) is a Java Message Service. It provides standard interfaces for generating, sending, and receiving messages, simplifying the development of enterprise applications. It supports two message communication models: point-to-point (P2P) model and pub/Sub Model. The P2P model specifies that a message can only have one receiver; pub/sub
The model allows a message to have multiple receivers.
For point-to-point modelsAfter the message producer generates a message, the message is sent to a queue, and then the Message Receiver reads the message from the queue. Once the message is read by a receiver, it disappears in this queue, so a message can only be consumed by one receiver.
Different from the point-to-point model,Publish/subscribe ModelWhen a message producer generates a message and sends it to a topic, the topic can have multiple receivers listening at the same time. When a message arrives at this topic, all message recipients will receive the message.

Summary:In short, the difference between the point-to-point model and the publish/subscribe model is that the former is one-to-one, and the latter is one-to-many.

2. Several Important Concepts

1) destination: the destination of the message, that is, the queue and topic mentioned above. After a message is created, you only need to send the message to the destination, and the message sender can continue to do his/her own work without waiting for the message to be processed. When the message will be consumed by the consumer depends on the message recipient.

2) message: it can be seen from the literal that the message is sent. It has the following types:
A) streammessage: Java data stream message, which is sequentially filled and read by standard stream operations.
B) mapmessage: a message of the map type. Its name is of the string type, and its value is of the basic type of Java.
C) textmessage: A common string message that contains a string.
D) objectmessage: Object message, which contains a serializable Java object
E) bytesmessage: a binary array message that contains a byte [].
F) xmlmessage: an XML message.
Note: textmessage and objectmessage are commonly used.

3) Session: The session established with the JMS provider, through which we can create a message.
4) connection: A Connection established with the JMS provider. You can create a session from this connection, that is, session.
5) connectionfactory: how to create a connection? This requires the connectionfactory mentioned below. Through this factory class, you can get a connection with the JMS provider, that is, conection. 6) Producer: the producer of a message. To send a message, it must be sent by the producer.
7) messageconsumer: corresponds to the producer, which is the consumer or receiver of the message. It is used to receive a message.
The JMS provider has been mentioned many times before, because JMS only provides a series of interfaces. When we use a JMS, we still need a third-party provider, it is used to manage these connections, sessions, topics, and queue.

The following figure shows the relationship between these concepts.

Connectionfactory ----> connection ---> session ---> message
Destination + session ------------------------------------> producer
Destination + session ------------------------------------> messageconsumer

 
Someone may ask: Where can I get connectionfactory and destination?
This is related to the JMS provider. if it is in a javaee environment, it can be found through JNDI. If it is in a non-javaee environment, it can only be obtained through the interface provided to us by the JMS provider.
About JMS entry knowledge from: http://blog.csdn.net/zhangxs_3/article/category/625599


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.