gpt4 book ai didi

java - 使用消息使用者时的 JMS 自动确认

转载 作者:行者123 更新时间:2023-12-01 14:11:45 25 4
gpt4 key购买 nike

我遇到一种情况,我正在使用消息使用者 (javax.jms.MessageConsumer) 从队列中读取消息。使用的 session 正在使用 AUTO_ACKNOWLEDGE 模式。

据我目前所读到的有关 AUTO_ACK 模式的内容:

In auto acknowledgement if the consumer's onMessage() method completes without error the message is considered received and processed successfully, it'll be then removed from the JMS server.

我的问题是,考虑到我没有使用具有 onMessage() 方法的 MDB,而是使用前面描述的消息使用者来读取消息,JMS 生产者何时将消息视为 ACK。

当我使用 messageConsumer 成功读取消息后,该消息是否已被确认?如果在逻辑链的更下游,使用相应消息的方法将抛出错误,会发生什么?到那时该消息是否已经被确认?

最佳答案

AUTO_ACKNOWLEDGE 常量的 Javadoc 是这样说的:

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.

我怀疑您正在 MessageConsumer 上调用 receive (尽管您没有明确说明),因此如果您设置 AUTO_ACKNOWLEDGE ,它将在接收返回时得到确认。

当然,如果您有事务 session ,则确认模式将被忽略,并且在 session 提交之前不会认为已收到消息。

关于java - 使用消息使用者时的 JMS 自动确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18484453/

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