DefaultMessageListenerContainer的Javadoc说
强烈建议将“sessionTransacted”设置为“true” 或指定外部“transactionManager”。
为什么强烈推荐?这个神秘建议的背后是什么?
答案 0 :(得分:1)
如果您的会话未被处理,则在JVM意外关闭的情况下,您可能会丢失邮件。
以下是AbstractMessageListenerContainer的各种确认模式的解释:
侦听器容器提供以下消息确认 选项:
"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.
确切的行为可能因具体的听众而异 使用容器和JMS提供程序。
由于消息传递通常基于有保证的传递,因此建议使用提供最佳安全措施以防止邮件丢失的方法。如果它值得,你必须决定一个特定的用例。