2
votes

conditions:

1) use a hibernate transaction manager 2) queue is marked as transactional 3) use the SimpleMessageListenerContainer that comes bundles with spring-amqp to trigger a consumer of the message.

scenario :

A consumer generates an exception due to some unexpected error which causes the hibernate transaction to rollback, and the message to be requeued. This is taken care of by the container.

Due to the way that the SimpleMessageContainer is written i could not find a way to remove the message from the queue and & have the platform transaction manager rollback. Either the channel & transaction manager both roll back or the operation passes.

What i thought of doing was to mark the message as failed on an exception by populated a field on the message, so that when it comes back to another consumer i can analyse the state of the message using AOP advice and then reroute the message to another exchange.

I can not seem to alter the body of the message, or add in a header to tag the message in rabbitmq. Each time the message comes back in it is the original one.

How can i tag the message ?

How have other people managed to solve the rerouting of messages on an exception whilst rolling back the transaction ?

1

1 Answers

0
votes

There is a queue argument named "x-dead-letter-exchange" that is used to specify an exchange to wich messages will be republished if they are rejected or expire.