2.6, ActiveMQ message confirmation mechanism -ACK

Copyright Notice: Welcome to reprint exchange, to declare the source. Performance status prior to the state of mind, habits prior to determination, focus first on preferences --Bestcxx https://blog.csdn.net/bestcxx/article/details/90551495

Foreword

Performance status prior to the state of mind, habits prior to determination, focus first on preferences

ACK (Acknowledgement) acknowledgment character

Transmission and reception of messages in the messaging middleware is a very common scenario, then our program during the interaction and messaging middleware is how the confirmation process is completed it? Such as producer sends a message to the messaging middleware how to tell the messaging middleware has been sent? another example from consumers get a message from the message middleware, messaging middleware is how to confirm the consumer has successfully processed the message?
This relates to the confirmation message status, namely ACK, detailed below

JMS defines four types of ACK

As JAVA JMS Message Service API defined in javax.jms.Sessionthe ACK defines four types

/**生产者或者消费者端设置,自动确认模式,也是默认级别,只要消息被发送完毕,或者接受完毕即算完成*/
static final int AUTO_ACKNOWLEDGE = 1;
/**仅在消费者端配置,需要消费者端调用 message.acknowledge() 进行消息确认*/
static final int CLIENT_ACKNOWLEDGE = 2;
/**仅在消费端配置,批量消息确认模式,有可能造成消息中间件无法及时收到消息被客户端正确处理的情况,依据消息重试策略可能造成消息重复消费*/
static final int DUPS_OK_ACKNOWLEDGE = 3;
/**生产者或者消费者端设置,需要开始事务*/
static final int SESSION_TRANSACTED = 0;

ActiveMQ one more than the ACK ACK type

ActiveMQ follow JMS standard, but also to achieve other protocols AMQP etc., in addition to these four types JMS defined ACK, which org.apache.activemq.ActiveMQSessionalso defines a separate ACK Type

* 翻译:在 INDIVIDUAL_ACKNOWLEDGE 模式下,每次 调用 message.acknowledge() 仅会确认
* 一条消息,作为对比,在 CLIENT_ACKNOWLEDGE 模式下,在一个 session 中可以一次消费多个消息
* ,但是仅调用一次 acknowledge() 即可表示对所有消息的确认
* 
* Only acknowledge an individual message - using message.acknowledge()
* as opposed to CLIENT_ACKNOWLEDGE which
* acknowledges all messages consumed by a session at when acknowledge()
* is called
*/
public static final int INDIVIDUAL_ACKNOWLEDGE = 4;

JmsTemplate CLIENT_ACKNOWLEDGE mode is not supported?

After the discussion, we can see the face of the client can consume the message to confirm the message by calling message.acknowledge (), but in JmsTemplate providing method, even if you have been to this configuration, the client can not go calling message.acknowledge (), the message seems to always be submitted by default, why?

Spring JmsTemplate as a template to provide messaging services, the significance of its existence is to be dispensed without having to configure the vast majority, so by default it will automatically commit the transaction JmsTemplate that AUTO_ACKNOWLEDGE mode
you can think of JDBC is not also such a thing when using Mybatis the transaction is submitted by default, unless you use the transaction configuration. for JmsTemplate, if you want to join the transaction configuration, also need to add a separate configuration

So, if you want to manually confirm the news, it is still nice to use ActiveMQ provides, if you use JmsTemplate then either accept the default message confirmation mechanism, either a new transaction configuration, so at least you can roll back the message about these implementation will be presented below.

Guess you like

Origin blog.csdn.net/bestcxx/article/details/90551495