JMS study notes (1) basic concepts.

Basic Concepts

JMS is a Java message service, and JMS clients can perform asynchronous message transmission through the JMS service.

Its features

1. Write clients in multiple languages ​​and protocols. Languages: Java, C, C++, C#, Ruby, Perl, Python, PHP. Application protocols: OpenWire, Stomp REST, WS Notification, XMPP, AMQP
fully supports JMS1.1 and J2EE 1.4 specifications (persistence, XA messages, transactions)

2. Support for Spring, ActiveMQ can be easily embedded into systems using Spring 3. Passed the

test of common J2EE servers (such as Geronimo, JBoss 4, GlassFish, WebLogic), and through the configuration of JCA 1.5 resource adaptors, ActiveMQ can be automatically deployed to any Compatible with 4. J2EE 1.4 on commercial servers,
supports multiple transmission protocols: in-VM, TCP, SSL, NIO, UDP, JGroups, JXTA

5. Supports high-speed message persistence through JDBC and journal

6. It is designed to ensure high High - performance

cluster , client-server, point - to -point ) ○ Publish/Subscribe(Pub/Sub)









That is , the concepts involved in the point-to-point and publish-subscribe model

P2P 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. Features of P2P There is only one consumer (Consumer) per message (that is, once consumed, the message is no longer in the message queue) There is no time dependency between the sender and the receiver, that is, when the sender sends After the message, whether the receiver is running or not, it will not affect the message being sent to the queue. If the receiver is not running, it will be held until the receiver is running. 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 P2P mode. Concepts involved in Pub/Sub Topic (Topic) Publisher (Publisher) Subscriber (Subscriber) The client sends messages to the topic. Multiple publishers send messages to topics, and the system delivers these messages to multiple subscribers. Features of Pub/Sub Each message can have multiple consumers. When a message is subscribed, it will be sent to all interested subscribers, so zero to many subscribers will receive a copy of the message. But when a message is received by the message broker, only the active subscriber can get a copy of the message.































There is a time dependency between publishers and subscribers. For a subscriber of a topic (Topic), it must create a subscriber before it can consume the message of the publisher, and in order to consume the message, the subscriber must keep the running state.
To ease such strict time dependencies, 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 messager, or can be processed by multiple consumers, then you can use the Pub/Sub model.

Message consumption
In JMS, message generation and message are Asynchronous. For consumption, JMS messagers can consume messages in two ways.
○ Synchronization
Subscribers or receivers call the receive method to receive the message, and the receive method will block until the message can be received (or until the timeout). When called synchronously, ACK is called before the message returns from the receive method; therefore, if the client does not process successfully, the message will be lost (possibly retransmitted, related to ACK_MODE).

○ Asynchronous A
subscriber or receiver can be registered as a message listener. When the message arrives, the system automatically calls the listener's onMessage method. When based on an asynchronous call, the confirmation of the message is after the onMessage method returns. If the onMessage method is abnormal, the message will be resent.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326692381&siteId=291194637