jNayden
jNayden

Reputation: 1620

ServiceMix, Apache ActiveMQ, Camel sending "done" for consuming messages

The issue I have is this: using service mix and camel routing I am sending a JSON message via activeMQ to consumer. The issue is that the time that this consumer takes to process this message is X so it is possible the consumer get stopped or crashed during the consuming of the message. In this case the message will be half consumer and will be already deleted from the queue because well it was delivered.

Is it possible to make the queue to not remove messages when they are consumed but instead to wait for some confirmation from the consumer that the processing of this message is done before deleting it?

In a typical importing files from filesystem you will remove the file or rename it to done only at the end ones the file is fully processed and a transaction is fully committed. So how in the ESB world we can say keep the message till I finish and I tell you to remove it.

i am using spring jms:listener-container and jms:listeners for consuming this messages currently.

Upvotes: 0

Views: 612

Answers (1)

Petter Nordlander
Petter Nordlander

Reputation: 22279

Your problem is what JMS transactions solves every day.

Some notes from ActiveMQ about it here

You could easily use local transactions in JMS, and setup a listener container like this (note true on sessionTransacted):

<bean id="myListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="1" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
    <property name="destination" ref="myQueue" />
    <property name="messageListener" ref="myConsumerBean" />
    <property name="sessionTransacted" value="true" />
</bean>

Then you have a transacted session. The message will be rolled back to the queue if the message listener fails to consume the message. The transaction will not commit(=message removed from queue) unless the "onMessage" method in the message listener bean returns successfully (no exceptions thrown). I guess this is what you want

Upvotes: 1

Related Questions