gpt4 book ai didi

java - JMS 自动确认消费者处理发生在 onMessage 中

转载 作者:行者123 更新时间:2023-12-01 17:21:19 31 4
gpt4 key购买 nike

我无法理解 JMS AutoAck 上的以下观点网站:AUTO_ACKNOWLEDGE 遵循以下行为

Right after the onMessage method returns successfully after invoking the consumer's MessageListener (which might still in progress as per my understanding)

但根据我的理解,Consumer 实现了 MessageListener 并在 onMessage() 方法(由 Consumer 实现)中完成所有处理

还有一个问题:我无法理解 AUTO_ACKNOWLEDGEDUPS_OK_ACKNOWLEDGE 之间的差异。
我读到的是:DUPS_OK_ACKNOWLEDGE 懒惰地确认并可能再次传递相同的消息,但无法理解其实际含义。
请帮助我提供一个实际示例,其中需要 AUTO_ACKNOWLEDGE 以及需要 DUPS_OK_ACKNOWLEDGE

<小时/>

于 2013 年 9 月 5 日添加:从 Java Redeliver and transaction 添加一个点

Consider a failure occurring during message processing. What happens to the message? Will the message be lost or redelivered for successful processing later? The answers to these questions depend upon the transaction options you choose.

最佳答案

来自Transaction and redelivery in JMS的一些引述

<小时/>

Auto mode: When a session uses auto mode, the messages sent or received from the session are automatically acknowledged. This is the simplest mode and expresses JMS's power by enabling once-only message delivery guarantee.

阅读消息也意味着确认。所以 AUTO_ACKNOWLEDGE 很简单。但是,如果您使用没有 setMessageListenerQueueReceiver,并且消息处理失败,则消息会丢失。

<小时/>

Duplicates okay mode: When a session uses duplicates okay mode, the messages sent or received from the session are automatically acknowledged just like auto mode, albeit lazily. Under rare circumstances, the messages might be delivered more than once. This mode enables at-least-once message delivery guarantee.

AUTO_ACKNOWLEDGE类似,开销较少,但应用程序必须能够处理重复消息。如果性能很重要并且重复消息不是问题,您可以使用它。

<小时/>

Client mode: When a session uses client mode, the messages sent or received from the session are not acknowledged automatically. The application must acknowledge the message receipt. This mode gives the application (rather than the JMS provider) complete control over message acknowledgement, at the cost of increased code complexity.

使用这种方法,如果您处理一条消息,并且在完成此任务后,您显式调用 message.acknowledge()。如果处理过程中发生异常,消息不会丢失(会重新投递)。

<小时/>

关于你的问题的第一部分,请查看Javadoc AUTO_ACKNOWLEDGE 。引用:

With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message

either when the session has successfully returned from a call to receive

or when the message listener the session has called to process the message successfully returns.

链接的文章符合此描述(仅在 onMessage 成功时确认)。

我已经使用 JBoss 7 进行了测试,使用 AUTO_ACKNOWLEDGEMessageListener:如果 onMessage 中出现异常,消息实际上是未重新投递

关于java - JMS 自动确认消费者处理发生在 onMessage 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18567247/

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