What is JMS in spring?

Programmers look at the source code as a necessary condition for growth. Recently, they have been looking at the source code of spring and saw that a module in the spring framework is JMS. So what exactly is JMS? Let's understand it in several steps.

1. What is JMS? And the role of JMS.

JMS: Java Message Service (Java Message Service) application programming interface, is a Java platform about message-oriented middleware (MOM) API, used to send messages between two applications or distributed systems, asynchronous Communication.

For example, two applications need to transmit messages, we can use JMS service to transmit messages, and decouple the two applications by using JMS. Java Message Service is an API that has nothing to do with a specific platform, and most MOM providers support JMS. And the message will not be created repeatedly, ensuring the reliability of the message.

2. JMS message model.

JMS has two communication modes: point-to-point and publish/subscribe communication model. Before the advent of JMS api, most products used one of the communication models for communication. JMS api defines the specifications of the two communication models and provides a common interface to ensure that we use applications based on JMS api to be suitable for any kind model.

a. Point-to-point communication model

What is JMS in spring?

Point-to-point communication model

In the point-to-point communication model, the application consists of a message sender, a queue, and a message receiver. The message sender puts the message in the queue, and the message receiver gets the message from the queue, and then returns a successful response to the queue. When the message in the queue is acquired or timed out, the message in the queue has no meaning. In this model, the message receiver and the message sender do not affect each other, whether the message is received does not affect the sending of the message, and vice versa. In this model, each message has only one message receiver.

b. Publish/Subscribe Model

What is JMS in spring?

Publish/subscribe model

There can be multiple clients in the publish-subscribe model. The message publisher sends the message to the topic, and the message is passed to all clients through the topic, that is, the message subscriber. The publisher and the message subscriber are anonymous, but here In this mode, the subscriber (and the object that consumes the message) must exist and run all the time before the publisher can publish the message. Topic is mainly used to save and deliver messages, and will save the message until the message is delivered to the client. JMS allows subscribers to create a durable subscription so that even if the subscriber is not activated (running), it can receive messages from the publisher.

3. JMS programming model.

What is JMS in spring?

JMS programming model

The JMS application consists of these modules:

a. Administered objects

The management object is the JMS object pre-configured by the system administrator, which mainly manages the two objects of Connection Factories and Destination. The connection factory is to provide the connection service between the JMS service provider and the client. The destination is the specified location to which the consumption is sent.

b. Connection objects (Connections)

The connection object encapsulates the virtual connection with the JMS provider.

c. Sessions

Used to produce and consume messages, you can create message producers and message consumers.

d. Message Producers (Message Producers)

The message producer is created by the Session and is used to send messages to the destination.

e. Message Consumers

The message consumer is created by the Session to receive the message sent by the destination.

f. Message Listeners

The JMS message listener is the default event handler of the message and is used to define the processing actions after the message arrives.

4. The five message bodies of the message.

A JMS message consists of a message header and a message body. The message body contains five types, namely simple text (TextMessage), serializable objects (ObjectMessage), attribute collection (MapMessage), byte stream (BytesMessage), and original value stream. (StreamMessage), there are also messages without payload (Message).

Guess you like

Origin blog.csdn.net/wzs535131/article/details/107292552