Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 520
Urbanleg Avatar asked Oct 20 '22 19:10

Urbanleg


1 Answers

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

like image 61
M. Deinum Avatar answered Oct 23 '22 23:10

M. Deinum