I am trying to use Camel to consume a single message from a JMS queue in a transacted manner. Specifically in a flow like this:
- Wait until message is published on JMS queue
- Try to consume and process the single message
- If processing fails (exception occurs), rollback the consumption
- If the processing passes, acknowledge and stop consuming anymore messages
- Later in the application lifecycle, another process triggers consumption to start again from (1)
At first I tried to do this using a polling consumer, using the ConsumerTemplate, but I can't figure out if its possible to do this transactionally - it seems like the transaction is internal to the ConsumerTemplate so regardless of what I do the message is already acknowledged as consumed by the time the ConsumerTemplate returns.
Can I do this using the ConsumerTemplate? Can I do this using Camel and if so what is the best approach (Simple examples would be appreciated)?