[ https://issues.apache.org/jira/browse/ARTEMIS-4520?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justin Bertram updated ARTEMIS-4520: ------------------------------------ Description: I've stumbled into an issue with client acknowledge mode when using the JMS API. Here's an example: {code:java} try (var factory = new ActiveMQConnectionFactory("<broker-url")) { try (var ctx = factory.createContext("<user>", "<password>", JMSContext.CLIENT_ACKNOWLEDGE)) { var destination = ctx.createQueue("<destination>"); try (var consumer = ctx.createConsumer(destination)) { var message1 = consumer.receive(100000); // suppose this call returns real message var message2 = consumer.receive(100000); // suppose this call times out, so NULL is returned ctx.acknowledge(); // I'm expecting that message1 gets acknowledged here, but it's not happening /* Do something here... */ } } }{code} The reason for ack not working is that the implementation of {{JMSConsumer.receive}} stores the latest returned value in {{org.apache.activemq.artemis.jms.client.ActiveMQJMSContext}} for future usage in its {{acknowledge}} implementation. This happens regardless if the value is {{null}} or not. So in case the latest call to receive a message returns {{null}} then calling {{JMSContext.acknowledge()}} does nothing. was: I've stumbled into an issue with client acknowledge mode when using the JMS API. Here's an example: {code:java} try (var factory = new ActiveMQConnectionFactory("<broker-url")) { try (var ctx = factory.createContext("<user>", "<password>", JMSContext.CLIENT_ACKNOWLEDGE)) { var destination = ctx.createQueue("<destination>"); try (var consumer = ctx.createConsumer(destination)) { var message1 = consumer.receive(100000); // suppose this call returns real message var message2 = consumer.receive(100000); // suppose this call times out, so NULL is returned ctx.acknowledge(); // I'm expecting that message1 gets acknowledged here, but it's not happening /* Do something here.... */ } } }{code} The reason for ack not working is that the implementation of {{JMSConsumer.receive}} stores the latest returned value in {{org.apache.activemq.artemis.jms.client.ActiveMQJMSContext}} for future usage in its {{acknowledge}} implementation. This happens regardless if the value is {{null}} or not. So in case the latest call to receive a message returns {{null}} then calling {{JMSContext.acknowledge()}} does nothing. > JMSContext.acknowledge() doesn't work if last message received is null > ---------------------------------------------------------------------- > > Key: ARTEMIS-4520 > URL: https://issues.apache.org/jira/browse/ARTEMIS-4520 > Project: ActiveMQ Artemis > Issue Type: Bug > Reporter: Justin Bertram > Assignee: Justin Bertram > Priority: Major > > I've stumbled into an issue with client acknowledge mode when using the JMS > API. Here's an example: > {code:java} > try (var factory = new ActiveMQConnectionFactory("<broker-url")) { > try (var ctx = factory.createContext("<user>", "<password>", > JMSContext.CLIENT_ACKNOWLEDGE)) { > var destination = ctx.createQueue("<destination>"); > try (var consumer = ctx.createConsumer(destination)) { > var message1 = consumer.receive(100000); // suppose this > call returns real message > var message2 = consumer.receive(100000); // suppose this > call times out, so NULL is returned > ctx.acknowledge(); // I'm expecting that message1 gets > acknowledged here, but it's not happening > /* > Do something here... > */ > } > } > }{code} > The reason for ack not working is that the implementation of > {{JMSConsumer.receive}} stores the latest returned value in > {{org.apache.activemq.artemis.jms.client.ActiveMQJMSContext}} for future > usage in its {{acknowledge}} implementation. This happens regardless if the > value is {{null}} or not. So in case the latest call to receive a message > returns {{null}} then calling {{JMSContext.acknowledge()}} does nothing. -- This message was sent by Atlassian Jira (v8.20.10#820010)