F.O.O
F.O.O

Reputation: 4960

JMS Queues: Re-inserting a message vs Rolling Back

I have a JMS consumer that processes transactions against a third-party service.

When there is an exception calling this third party service e.g a java.net.ConnectException. I would like this message to be redelivered by the queue.

Redelivering can be done in two obvious approaches.

  1. Roll-back the transaction context: The queue redelivers the message but the JPA transaction is rolled back (however, I want the db to have a record of the transaction to prevent duplicate messages if any).

  2. Resend the message from the consumer with a redelivery time: The transaction context is preserved (record is saved in the db).

Are there any performance issues with re-sending messages from the consumer into the queue as opposed to not acknowledging them?

Upvotes: 0

Views: 591

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

It's more reliable to rollback.

You should simply start a new transaction for the DB update instead of synchronizing it with the JMS transaction, so the DB transaction commits even if the JMS transaction rolls back.

Upvotes: 2

Related Questions