Message Service -JMS

Message service
message service refers to an asynchronous communication between two application API, which provides a common interface for the standard message protocols and message services, including create, send, read messages, etc., to support application development . In Java, when two JMS application uses to communicate between them are not directly connected, but are connected together through a common messaging service, the decoupling effect can be achieved.

The JMS
the JMS Java Message Service i.e. (Java Message Service) application programming interface, a Java platform (MOM- distributed system integration) on a message-oriented middleware API, is used between the two applications, or distributed message transmission system, asynchronous communication.
JMS is a vendor-independent API, used to access the messaging system message that is similar to JDBC (Java Database Connectivity).

Architecture

JMS provider: connection-oriented message middleware, a JMS interfaces implemented. The JMS provider may be implemented in the Java platform, message-oriented middleware may be non adapter Java platform.

JMS client: the production or consumption of Java applications or message-based objects.

JMS Manufacturer: JMS clients to create and send messages.

JMS consumer: JMS client to receive messages.

JMS message: including an object that can be transmitted between JMS clients data.

JMS queues: an area receiving those messages waiting to be transmitted is read. Unlike the name implies queue means, receiving the order message is not necessarily the same as the transmission order of the messages. Once a message has been read, the message will be removed from the queue.

JMS Topic: kind of support mechanism to send messages to multiple subscribers.

JMS Object Model

 

 


ConnectionFactory connection factory
a virtual connection between a client and the package Connection Provider the JMS
the Session production and consumption of a single-threaded context message; means for creating Producer, Consumer, Message, Queue .. \
the Destination sending a message or a message receiving destination
MessageProducer / consumer news producer / consumer

Model JMS messages
in the JMS specification, there are two message model PTP (Point to Point), Publish / Subscribe (Pub / Sub).
The PTP:
1. If the session is closed when, some message has been received, but not sign, then the next time when the consumer is connected to the same queue, the message will be sign
2. If the user sets the receive process message selection criteria, it does not meet the conditions of the message will remain in the queue will not be received
3. message queue can be stored for a long time until the message is sign consumers. Consumers do not need to worry because the message is lost and keep connected with the jms provider status
Pub / Sub:
1. subscription can be divided into non-durable subscriptions and durable subscriptions
2. When all messages must be received, you need to use durable subscriptions. On the contrary, the non-durable subscription

Receiving a message
synchronization: synchronous mode to receive a message, then the message subscriber call receive () method. In the receive (), the message does not reach the specified time or before, the method will be blocked until a message is available.
Asynchronous: receives messages asynchronously, then the message subscribers need to register a message listener, similar to an event listener, as long as the message arrives, JMS providers will () delivered by calling the listener's onMessage message

JMS message structure (the Message)
the Message consists of three parts, namely the Header, Properties, Body, in detail as follows:

Header message header format for all types of this section are the same

Properties property, can be classified according to the nature of the application set, the standard properties and attributes defined message middleware

Body text messages, what we refer to the specific needs of message transmission.

Guess you like

Origin www.cnblogs.com/snow1314/p/12499616.html