Matthew Daws
Matthew Daws

Reputation: 1947

Trying to stop a message-driven-channel-adapter but droppping a message

I'm trying to stop a message-driven-channel-adapter using the SmartLifecycle stop method, but maybe 1/3 of the time, this results in the warning message:

DefaultMessageListenerContainer - Rejecting received message because of the listener container having been stopped in the meantime

Examining ActiveMQ suggests that the message really has been lost.

I'm using a JmsTemplate to get ActiveMQ to talk to Spring Integration. My beans look something like:

<bean id="Topic" class="org.apache.activemq.command.ActiveMQQueue">...</bean>
<bean id="archiveTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="defaultDestination" ref="Topic"></property>
    ...
</bean>
<si:channel id="InputChannel" />
<jms:message-driven-channel-adapter
    id="archiveInboundAdapter" channel="InputChannel" destination="Topic" />
<si:service-activator id="archiveConsumerActivator"
    input-channel="InputChannel" ref="consumer" method="onMessage" />

Then in my code I fetch the archiveInboundAdapter bean and call stop() on it.

Any ideas? Is there a better way to stop the receiving of messages? In reality, I'm trying to just handle a shutdown of the system in an orderly way (stop receiving messages, stop a complicated system of threads which process those messages, exit).

Upvotes: 2

Views: 595

Answers (1)

Gary Russell
Gary Russell

Reputation: 174739

Set acknowledge="transacted" so that in-flight messages are rolled back onto the queue.

Upvotes: 1

Related Questions