2
votes

Why are JMS messages acknowledged after onMessage() listener method returns even if acknowledgment mode is set to CLIENT_ACKNOWLEDGE?

If you look at the commitIfNecessary method in the AbstractMessageListenerContainer class, you can see the following:

protected void commitIfNecessary(Session session, Message message) throws JMSException {
    // Commit session or acknowledge message.
    if (session.getTransacted()) {
        // Commit necessary - but avoid commit call within a JTA transaction.
        if (isSessionLocallyTransacted(session)) {
            // Transacted session created by this container -> commit.
            JmsUtils.commitIfNecessary(session);
        }
    } else if (message != null && isClientAcknowledge(session)) {
        message.acknowledge();
    }
}

After debugging, I confirm that message.acknowledge() is called.

I thought that CLIENT_ACKNOWLEDGE means I need to acknowledge message manually?

Any idea?

Thanks, Mickael

1

1 Answers

2
votes

In this context, the message listener container is the client, not your listener.

If you wish to manually ack (perhaps after receiving a number of messages), don't use a listener container; you can use a JmsTemplate.execute() with a SessionCallback and create your own consumer.