Home  >  Article  >  php教程  >  Related understanding of Session settings in ActiveMQ

Related understanding of Session settings in ActiveMQ

高洛峰
高洛峰Original
2016-11-22 13:14:292561browse

Reference blog post: http://www.cnblogs.com/SzeCheng/p/4792084.html

Reference blog post: http://activemq.apache.org/producer-flow-control.html

Explanation of terms:

P: Producer

C: Consumer

Server: P or ActiveMQ service

Client: ActiveMQ service or C

The sign that the client successfully receives a message is that the message has been signed. Successfully receiving a message generally includes the following three stages:

1. The client receives the message;

2. The client processes the message;

3. The message is signed.

session = connection.createSession(Boolean.false, Session.CLIENT_ACKNOWLEDGE);##第一个参数控制事务,第二个参数控制消息

In a Session without transactions, when and how a message is signed depends on the Session settings.

1. Session.AUTO_ACKNOWLEDGE

When the client returns successfully from receive or onMessage, Session automatically signs the client's receipt of this message.

2. Session.CLIENT_ACKNOWLEDGE

The client signs the message by calling the acknowledge method of the message.

message.acknowledge();

In a Session with a transaction, the signature automatically occurs when the transaction is submitted. If the transaction is rolled back, all received messages will be delivered again. In fact, Session.CLIENT_ACKNOWLEDGE here is of little use.

session = connection.createSession(Boolean.TRUE, Session.CLIENT_ACKNOWLEDGE);
session.commit();

Summary:

1. For the producer: the server is P and the client is ActiveMQ service. Session is set to AUTO_ACKNOWLEDGE and CLIENT_ACKNOWLEDGE. Relatively speaking, the difference is not very big. It depends on the situation.

2. For consumers: the server is ActiveMQ and the client is C. The Session is set to AUTO_ACKNOWLEDGE. When a message is received (receive or onMessage returns successfully), the consumption is successful, and the data is removed from the queue. We don't care whether the data is correctly processed into the results we want; when the Session is set to CLIENT_ACKNOWLEDGE, the acknowledge method must be manually called for successful consumption, and then the data is removed from the queue.

3. Which mode the Sessions of P and C are set to have no influence on each other.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn