gpt4 book ai didi

java - ActiveMQ 中消费者的确认

转载 作者:行者123 更新时间:2023-11-29 03:49:13 24 4
gpt4 key购买 nike

我正在使用 ActiveMQ 编写 Java 应用程序。我有一个生产者类(接受用户输入)和一个带有监听器的消费者类,因此一旦消息到达,消息监听器就会执行 onMessage(msg) 函数。不过,我的问题是,消费者何时将确认发送回代理,以便消息从代理中出队?是onMessage(msg)函数中写的 Action 完成后还是onMessage(msg)函数被调用时?

最佳答案

取决于它是如何配置的,部分取决于你如何use transactions .

您使用的是消息驱动的 bean 吗?在那种情况下,我相信确认将在交易成功提交时发送。查看specification (特别是“ejbcore”版本),5.4.14 JMS Message-Driven Beans 的 Message Acknowledgement 部分说:

Message acknowledgment is automatically handled by the container. If the message-driven bean uses container-managed transaction demarcation, message acknowledgment is handled automatically as a part ofthe transaction commit.

接着说:

If bean-managed transaction demarcation is used, the message receipt cannot be part of the bean-managed transaction, and, in this case, the receipt is acknowledged by the container. If bean-managed transaction demarcation is used, the Bean Provider can indicate whether JMS AUTO_ACKNOWLEDGE semantics or DUPS_OK_ACKNOWLEDGE semantics should apply by using the activationConfig element of the MessageDriven annotation or by using the activation-config-property deployment descriptor element.

但由于您真的不应该使用 bean 管理的事务,所以希望这无关紧要。

关于java - ActiveMQ 中消费者的确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9532948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com