[ https://issues.apache.org/jira/browse/AMQ-6454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15551871#comment-15551871 ]
Yuriy commented on AMQ-6454: ---------------------------- Gary, I think having message.acknowledge() fail if a consumer was already closed can be considered as workaround, which prevents unexpected redelivery (in other words duplication of messages). But this type of fix will not make behavior compliant to JMS specification. You are right: JMS session should not be shared across threads. But JMS specification explicitly states that method close() is the only method of message consumer and session, which can be called concurrently: https://docs.oracle.com/javaee/7/api/javax/jms/MessageConsumer.html#close-- https://docs.oracle.com/javaee/7/api/javax/jms/Session.html#close-- That's why consumer.close() is frequently used from another thread to make consumer.receive() return. In the described use case both receive() and acknowledge() methods are invoked from the same thread. Method close() is invoked from another thread. Therefore it is absolutely valid use case. Thread1 : Message message = consumer.receive(); Thread2 : consumer.close(); Thread1: message.acknowledge(); I think that till the next major release of ActiveMQ some configuration option that will allow to switch to legacy behavior (or otherwise to the new behavior) would be acceptable solution for all ActiveMQ users. > Message is redelivered after succesfull acknowledge() > ----------------------------------------------------- > > Key: AMQ-6454 > URL: https://issues.apache.org/jira/browse/AMQ-6454 > Project: ActiveMQ > Issue Type: Bug > Affects Versions: 5.14.1 > Reporter: Yuriy > Attachments: activemq-bug.zip > > > JMS message is redelivered after successful call of acknowledge(). > The following methods are invoked: > Thread1 : Message message = consumer.receive(); > Thread2 : consumer.close(); > Thread1: message.acknowledge(); > All the methods return successfully but the message is redelivered on the > next receive() call. Note that consumer.close() is typically used to force > consumer.receive() to return. > According to JMS specification the scope of message acknowledge() call is > session (not message consumer): > https://docs.oracle.com/javaee/7/api/javax/jms/Message.html#acknowledge-- > A simple program to reproduce the bug is attached. > Observed behavior: > Message is redelivered. > Program output: > ============ > Message sent. Id=ID:comp-63860-1475602285903-1:1:1:1:1 > Message received. Id=ID:comp-63860-1475602285903-1:1:1:1:1. Text=Welcome! > Message succesfully acknowledged > Message received. Id=ID:comp-63860-1475602285903-1:1:1:1:1. Text=Welcome! > Message succesfully acknowledged > Expected behavior: > Message should be delivered only once. -- This message was sent by Atlassian JIRA (v6.3.4#6332)