Lewis Wong
Lewis Wong

Reputation: 269

Camel JMS with CLIENT_ACKNOWLEDGE mode not working

I am unable to acknowledge JMS message with CLIENT_ACKNOWLEDGE mode in camel. After digging a into the stack trace I found that message.acknowledge() in AbstractMessageListenerContainer is always being executed which causes the auto-ack behavior. Am I configured anything wrong?

org.springframework.jms.listener.AbstractMessageListenerContainer.commitIfNecessary(Session, Message)

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();
        }
    }

Spring Configuration

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory" ref="cachedConnectionFactory" />
    <property name="asyncConsumer" value="true" />
    <property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE" />
</bean>

<bean id="cachedConnectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="connectionFactory" />
    <property name="sessionCacheSize" value="30" />
</bean>

Camel Route

from(jmsTerminalRequest).routeId("generic-jms-inbound").setExchangePattern(ExchangePattern.InOnly).threads(5, 20, "generic-jms-inbound").bean(clientAckProcessor).to("...")

Upvotes: 0

Views: 4945

Answers (1)

nefo_x
nefo_x

Reputation: 3088

What you can do is specifying acknowledgement mode within route consuming endpoint definition:

from("...?maxConcurrentConsumers=20&acknowledgementModeName=CLIENT_ACKNOWLEDGE")
    .bean(clientAckProcessor)
    .to("...")

Upvotes: 1

Related Questions