简体   繁体   中英

XA transactions and message bus

In our new project we would like to achieve transactions that involve jpa (mysql) and a message bus (rabbitmq)

We started building our infrastructure with spring data using mysql and rabbitmq (via spring amqp module). Since rabbitMq is not XA-transactional we configured the neo4j chainedTransactionManager as our main transactionManager. This manager takes as argument the jpa txManager and the rabbitTransactionManager.

Now, I do get the ability to annotate a service with @Transacitonal and use both the jpa and rabbit inside it. If I throw an exception within the service then none of the actions actually occur.

Here are my questions:

  1. Is this configuration really gives me an atomic transaction?
  2. I've heard that the chained tx manager is not using a 2 phase commit but a "best effort", is this best effort less reliable? if so how?

What the ChainedTransactionManager does is basically start and commit transactions in reverse order. So if you have a JpaTransactionManager and a RabbitTransactionManager and configured it like so.

@Bean
public PlatformTransactionManager transactionManager() {
    return new ChainedTransactionManager(rabbitTransactionManager(), jpaTransactionManager());
}

Now if tha JPA commit succeeds but your commit to rabbitMQ fails your database changes will still be persisted as those are already committed.

To answer your first question it doesn't give you a real atomic transaction, everything that has been committed prior to the occurence of the Exception (on committing) will remain committed.

See http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/transaction/ChainedTransactionManager.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM