Andrei Pushkin
Andrei Pushkin

Reputation: 95

Transactions and asynchronous processing

Assume some spring bean has transactional method and it does two things:

The problem is that when the message is consumed, the DB transaction sometimes not have committed, and handler failed to find in DB expected value.

The evident solution - is to send in transaction, but I use async send available on ActiveMQ to increase throughput. If I make send transactional, I forfeit asynchrocity and also risk getting OuOfMemory.

How would you solve this problem?

Upvotes: 0

Views: 646

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

You need to use an XA-enabled transaction manager, and send the JMS message and do the update to the DB in the same, distributed transaction.

This doesn't change anything to asynchronicity: the send call will return before the receiver receives the message. But when it receives it, the transaction will be committed, and the receiver will find the updates in the database.

I don't see what OutOfMemoryErrors have to do with this.

Upvotes: 2

Related Questions