JMS two message models, point-to-point, publish-subscribe

 

JMS is a Java message service, and JMS clients can perform asynchronous message transmission through the JMS service. JMS supports two message models: Point-to-Point (P2P) and Publish/Subscribe (Pub/Sub), namely point-to-point and publish-subscribe models.

 

P2P

In the P2P model, there are the following concepts: message queue (Queue), sender (Sender), receiver (Receiver). Each message is sent to a specific queue, and the receiver gets the message from the queue. Queues hold messages until they are consumed or time out.

1. There is only one consumer (Consumer) for each message (that is, once consumed, the message is no longer in the message queue)

2. There is no time dependency between the sender and the receiver, that is to say, when the sender sends a message, whether the receiver is running or not, it will not affect the message being sent to the queue.

3. The receiver needs to reply to the queue successfully after receiving the message successfully

If you want every message you send should be processed successfully, then you need the P2P model.

 

Pub/Sub

In the Pub/Sub model, there are the following concepts: Topic, Publisher, and Subscriber. The client sends the message to the topic. Multiple publishers send messages to topics, and the system delivers these messages to multiple subscribers.

1. Each message can have multiple consumers

2. There is a time dependency between publishers and subscribers. For a subscriber of a topic (Topic), it must create a subscription before it can consume the publisher's messages, and, in order to consume messages, the subscriber must remain running. Of course, to alleviate this strict time dependency, JMS allows subscribers to create a durable subscription. This way, even if the subscriber is not activated (running), it can receive messages from the publisher.

If you want to send a message that can be processed without any processing, or processed by one consumer, or can be processed by multiple consumers, you can use the Pub/Sub model.

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326100456&siteId=291194637