2

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

Faxon
  • 21
  • 2

1 Answers1

0

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.

Kaj Hejer
  • 955
  • 4
  • 18
  • Thank you for your answer, maybe my question is not clear. Now my multiple TransactionManagers have been configured and working. Now I need to monitor one of the transactions. For example, after the transaction is submitted to execute some logic, I found that I can use the @TransactionalEventListener annotation processing, but I cannot bind it to I need the transaction manager – Faxon Mar 31 '21 at 08:29
  • @Faxon Thank you for the clarification. Sorry, but I can help you on that one. I would recommend you to update your question with the information in you last comment to make it easier for other to answer. – Kaj Hejer Mar 31 '21 at 08:32