@TransactionalEventListener how to bind TransactionManager

Viewed 235

There are multiple data sources in my project, and each data source corresponds to a transaction manager, and they share a single aspect. Now there is a problem in my project: some logic needs to be processed after the transaction is submitted, such as sending Mq messages. I tried to use @TransactionalEventListener implementation, but I found that in AbstractPlatformTransactionManager.processCommit(), he monitored the submission of other transactions. I am puzzled, is there any solution?How to use the condition in @TransactionEventListener? Spring Version 5.1.5.RELEASE

1 Answers

I'm not sure if this solves your issue, but one way of handling multiple TransactionManagers is to add an parameter to the @Transactional annotation telling which TransactionManager to use:

public class TransactionalService {

    @Transactional("order")
    public void setSomething(String name) { ... }

    @Transactional("account")
    public void doSomething() { ... }
}

Please see https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/transaction.html#tx-multiple-tx-mgrs-with-attransactional for more details.

Related