带有和不带有Spring JMS的AUTO_ACKNOWLEDGEMENT模式之间的区别 [英] Difference between AUTO_ACKNOWLEDGEMENT mode with and without Spring JMS

查看:169
本文介绍了带有和不带有Spring JMS的AUTO_ACKNOWLEDGEMENT模式之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解确认模式在JMS中的工作方式.我正在阅读此资源,但与Spring文档所说的相矛盾,这使我非常困惑.

I am trying to understand how acknowledgement modes work in JMS. I was reading this source and it hugely confused me as it was contradicting what Spring's documentation says.

有消息说一件事: 来自 http://www. javaworld.com/article/2074123/java-web-development/transaction-and-redelivery-in-jms.html

Sources saying one thing: From http://www.javaworld.com/article/2074123/java-web-development/transaction-and-redelivery-in-jms.html

成功从receive()方法返回消息后,将自动对其进行确认.如果接收者使用MessageListener接口,则从onMessage()方法成功返回该消息时,将自动对其进行确认.如果在执行receive()方法或onMessage()方法时发生故障,则会自动重新传递消息.

A message is automatically acknowledged when it successfully returns from the receive() method. If the receiver uses the MessageListener interface, the message is automatically acknowledged when it successfully returns from the onMessage() method. If a failure occurs while executing the receive() method or the onMessage() method, the message is automatically redelivered.

来自 http://www2.sys -con.com/itsg/virtualcd/Java/archives/0604/chappell/index.html

在AUTO_ACKNOWLEDGE模式下,确认始终是onMessage()处理函数返回后隐式发生的最后一件事.通过在使用会话上指定CLIENT_ACKNOWLEDGE模式,接收消息的客户端可以对保证消息的传递进行更细粒度的控制.

With AUTO_ACKNOWLEDGE mode the acknowledgment is always the last thing to happen implicitly after the onMessage() handler returns. The client receiving the messages can get finer-grained control over the delivery of guaranteed messages by specifying the CLIENT_ACKNOWLEDGE mode on the consuming session.

Spring Docs说了其他话: 来自 http://docs. spring.io/spring/docs/current/javadoc-api/org/springframework/jms/listener/AbstractMessageListenerContainer.html

Spring Docs saying other things: From http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/listener/AbstractMessageListenerContainer.html

侦听器容器提供以下消息确认选项:

The listener container offers the following message acknowledgment options:

将"sessionAcknowledgeMode"设置为"AUTO_ACKNOWLEDGE"(默认):在执行侦听器之前自动确认消息;如果发生异常,则不重新交付. "sessionAcknowledgeMode"设置为"CLIENT_ACKNOWLEDGE":成功执行侦听器后自动确认消息;如果发生异常,则不进行重新交付. "sessionAcknowledgeMode"设置为"DUPS_OK_ACKNOWLEDGE":在侦听器执行期间或之后执行惰性消息确认;如果引发异常,则有可能重新交付. "sessionTransacted"设置为"true":成功执行侦听器后的事务确认;确保在发生异常的情况下重新交付.

"sessionAcknowledgeMode" set to "AUTO_ACKNOWLEDGE" (default): Automatic message acknowledgment before listener execution; no redelivery in case of exception thrown. "sessionAcknowledgeMode" set to "CLIENT_ACKNOWLEDGE": Automatic message acknowledgment after successful listener execution; no redelivery in case of exception thrown. "sessionAcknowledgeMode" set to "DUPS_OK_ACKNOWLEDGE": Lazy message acknowledgment during or after listener execution; potential redelivery in case of exception thrown. "sessionTransacted" set to "true": Transactional acknowledgment after successful listener execution; guaranteed redelivery in case of exception thrown.

我想知道的是,为什么这些消息来源说的是不同的话?如果一切正确,那么我如何知道何时/何时确认我的消息?

What I want to know is that why these sources are saying different things? If all are true then How do I know how/when my message will be acknowledged?

推荐答案

您错过了抽象容器javadocs中的关键词...

You missed out the key phrase from the abstract container javadocs...

The exact behavior might vary according to the concrete listener container and JMS provider used.

Spring中最常用的侦听器容器是表现出该行为的DefaultMessageListenerContainer-它旨在与以下环境中的事务(本地或外部事务管理器)一起使用:以便能够回滚已确认的消息.在接收方法之后 会调用其侦听器,因此已经应用了标准的JMS自动确认.线程上的任何JmsTemplate操作也可以使用同一会话-因此可以成为事务的一部分.

The most commonly used listener container used in Spring is the DefaultMessageListenerContainer which does exhibit that behavior - it is intended for use with transactions (either local or an external transaction manager), in order to have the ability to roll back an already acknowledged message. Its listener is invoked after the receive method, so the standard JMS auto-ack has already been applied. Any JmsTemplate operations on the thread can also use the same session - and thus can be part of the transaction.

另一方面,SimpleMessageListenerContainer使用传统的MessageListener并表现出标准的JMS行为(在receive()返回之前从Consumer调用侦听器;因此,异常将停止确认).

On the other hand, the SimpleMessageListenerContainer uses a traditional MessageListener and exhibits the standard JMS behavior (the listener is called from the Consumer before receive() returns; thus exceptions will stop the ack).

我建议您阅读有关这些具体实现的javadocs.从SMLC ...

I suggest you read the javadocs for those concrete implementations. From the SMLC...

This is the simplest form of a message listener container. It creates a fixed 
number of JMS Sessions to invoke the listener, not allowing for dynamic 
adaptation to runtime demands. Its main advantage is its low level of 
complexity and the minimum requirements on the JMS provider: Not even the 
ServerSessionPool facility is required.

See the AbstractMessageListenerContainer javadoc for details on acknowledge 
modes and transaction options.

For a different style of MessageListener handling, through looped 
MessageConsumer.receive() calls that also allow for transactional reception of 
messages (registering them with XA transactions), see 
DefaultMessageListenerContainer.

我将为抽象容器上的文档打开JIRA问题,因为我看到它可能会误导人.

I will open up a JIRA issue for the docs on the abstract container because I can see that it might be misleading.

这篇关于带有和不带有Spring JMS的AUTO_ACKNOWLEDGEMENT模式之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆