简体   繁体   English

JMS自动确认使用者处理发生在onMessage中

[英]JMS auto acknowledgment consumer processing happens in onMessage

I am not able to understand the below point on JMS AutoAck website: The below behaviour is followed in AUTO_ACKNOWLEDGE 我无法理解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) 在调用使用者的MessageListener之后onMessage方法成功返回之后(根据我的理解,它可能仍在进行中)

but as per my understanding, the Consumer implements MessageListener and does all the processing in the onMessage() method (which is implemented by Consumer) 但据我了解,消费者实现了MessageListener并在onMessage()方法(由消费者实现onMessage()中进行了所有处理

One more question: I am not able to understand the diff between AUTO_ACKNOWLEDGE and DUPS_OK_ACKNOWLEDGE . 还有一个问题:我无法理解AUTO_ACKNOWLEDGEDUPS_OK_ACKNOWLEDGE之间的AUTO_ACKNOWLEDGE
What I read is : DUPS_OK_ACKNOWLEDGE acknowledges lazily and might deliver the same message again, but not able to understand its practical implications. 我读到的是: DUPS_OK_ACKNOWLEDGE懒惰地确认,并且可能会再次发送相同的消息,但无法理解其实际含义。
Please help me with a practical example where AUTO_ACKNOWLEDGE is required and where DUPS_OK_ACKNOWLEDGE required 请帮我举一个实际的例子,其中需要AUTO_ACKNOWLEDGE而需要DUPS_OK_ACKNOWLEDGE


Added 5th Sep13 :Adding a point from Java Redeliver and transaction 2013年9月5日添加:从Java 重新交付 和交易中添加一个点

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. 这些问题的答案取决于您选择的交易选项。

Some quotes from Transaction and redelivery in JMS 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. 这是最简单的模式,它通过启用仅一次消息传递保证来表达JMS的功能。

Reading a message means acknowledgement as well. 阅读消息也意味着确认。 So AUTO_ACKNOWLEDGE is simple. 因此, AUTO_ACKNOWLEDGE很简单。 But if you are using a QueueReceiver without setMessageListener , and message processing fails, the message is lost. 但是,如果您使用不带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. 此模式启用最少一次的消息传递保证。

Like AUTO_ACKNOWLEDGE , with less overhead, but the application must be able to deal with duplicate messages. AUTO_ACKNOWLEDGE一样,开销较小,但应用程序必须能够处理重复的消息。 You could use this, if performance matters, and duplicate messages are not a problem. 如果性能很重要,则可以使用此功能,并且重复消息不是问题。


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. 这种模式使应用程序(而不是JMS提供程序)可以完全控制消息确认,但以增加代码复杂性为代价。

Use this approach, if you process one message, and after you have completed this task, then you explicitly call message.acknowledge() . 如果处理一条消息,则使用此方法,并且在完成此任务之后,您将显式调用message.acknowledge() If an exception happens during processing, the message is not lost (it will be redelivered). 如果在处理过程中发生异常,则消息不会丢失(它将重新传递)。


As for the first part of your question, have a look at the Javadoc of AUTO_ACKNOWLEDGE . 至于问题的第一部分,请看一下AUTO_ACKNOWLEDGE的Javadoc。 A quote: 引用:

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. 或在会话已调用以处理消息的消息侦听器成功返回时。

The linked article conforms to this description (acknowledge only, if onMessage is successful). 链接的文章符合此描述(仅当onMessage成功时才进行确认)。

I have tested this using JBoss 7, using AUTO_ACKNOWLEDGE with a MessageListener : In case of an exception in onMessage , the message is actually not redelivered . 我已经使用JBoss 7,将AUTO_ACKNOWLEDGEMessageListener进行了测试:如果onMessage发生异常,则实际上不会重新传递消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM