gpt4 book ai didi

java - WMQ/JMS 无丢失和重复消息原理

转载 作者:行者123 更新时间:2023-11-30 08:24:05 25 4
gpt4 key购买 nike

如果 JMS 客户端应用程序要求不能丢失任何消息,也不能重复发送以供处理,并且每条消息与其他消息无关(无批处理),那么哪种组合可以满足这些要求:- 持久化+自动确认 session 模式(异步消费者)- 持久性+客户端确认 session 模式- 持久性+交易 session - 任何其他?我已经阅读了有关事务处理 session 和确认模式的信息(例如此处 http://docs.oracle.com/javaee/1.4/tutorial/doc/JMS6.html 和此处 http://wso2.com/library/articles/2013/01/jms-message-delivery-reliability-acknowledgement-patterns/ ),在我看来,所有三种可能性都是可以接受的。你同意?使用事务处理 session 或更高级的可靠性概念有什么优势?

提前致谢!

最佳答案

如果您正在通过网络与任何 JMS 传输提供者对话,请使用事务处理 session 并确保该应用检测并妥善处理重复消息。为什么?看看 JMS 1.1 specification4.4.13 消息的重复生产 部分中指出:

If a failure occurs between the time a client commits its work on a Session and the commit method returns, the client cannot determine if the transaction was committed or rolled back. The same ambiguity exists when a failure occurs between the non-transactional send of a PERSISTENT message and the return from the sending method.

It is up to a JMS application to deal with this ambiguity. In some cases, this may cause a client to produce functionally duplicate messages.

A message that is redelivered due to session recovery is not considered a duplicate message.

考虑一个通过网络发出 COMMIT 的应用程序。如果应用程序收到指示连接已断开的错误,它如何知道这是在 API 调用到达传输提供商之前还是之后发生的?如果应用正在发送消息,唯一安全的做法是假设 COMMIT 失败并重新发送消息。接收消息的事物将再次看到它。

类似地,如果应用接收到的消息在 COMMIT 上出现错误,那么如果该消息实际上已回滚,则会再次看到该消息。但是,应用程序不能假设它已回滚并丢弃它刚刚收到的消息,因为这可能会导致消息丢失。

因此 WMQ 或任何其他 JMS 传输提供程序不得传送欺骗,但由于网络引入的歧义,应用程序可能会收到欺骗。这是最好的情况,假设一个事务处理 session 并且应用程序可以优雅地处理欺骗。最坏的情况是,在事务处理 session 之外,歧义可能会导致应用丢弃消息。

关于java - WMQ/JMS 无丢失和重复消息原理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23201052/

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