FeeLGooD
FeeLGooD

Reputation: 505

JmsTemplate batch issue

my current use case is in my listener it will:

  1. Consume an event(let's call it original event) from queue, this event includes list of replay events(let's call it sub events).
  2. Produce those replay events (sub events) in a batch to other queue.
  3. Update Cassandra.

I can produce all the replay events based on what Gary mention, and rollback all the replay events if any exceptions happen during produce.

Use one of the execute methods with a ProducerCallback...

SessionCallback and ProducerCallback

Then, in your ProducerCallback.doInJms() method...

Use the producer to send multiple messages. When the callback exits, the transaction will be committed.

However, if there are any exception happen in step 3 we can only rollback the original event but not those replay events, since in step 2 we already committed those replay events after the callback exits and those replay events already in another queue and cannot be rollback.

Does someone has any better idea about how we can rollback everything if step 3 has exception?

Upvotes: 0

Views: 724

Answers (1)

Gary Russell
Gary Russell

Reputation: 174564

You have to do everything within the same session; consume, produce..., cassandra.

All inside doInJms()...

  • session.createConsumer()

try {

  • consumer.receive()
  • producer send() ...
  • cassandra update

finally {

  • consumer.close()

}

Upvotes: 2

Related Questions