XA operations and message bus

In our new project, we would like to receive transactions that include jpa (mysql) and message bus (rabbitmq)

We started building our infrastructure using spring data using mysql and rabbitmq (via the spring amqp module). Since rabbitMq is not an XA transaction, we configured neo4j chainedTransactionManager as our main transaction statement. This manager takes jpa txManager and rabbitTransactionManager as arguments.

Now I get the opportunity to comment on the service using @Transacitonal and use jpa and rabbit inside it. If I throw an exception, then in reality no action occurs.

Here are my questions:

  • Does this configuration really give me an atomic transaction?
  • I heard that the chanined tx manager does not use 2-phase commit, but the “best effort” is this better effort less reliable? if so, how?
+4
source share
1 answer

What it does ChainedTransactionManageris basically start and commit transactions in the reverse order. Therefore, if you have JpaTransactionManagerand RabbitTransactionManagerand configured so.

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

Now, if the JPA transaction is successful, but your commit to rabbitMQ fails, your changes to the database will still be saved as they are already committed.

To answer your first question, he will not give you a real atomic transaction, everything that was committed before the appearance Exception(upon completion) will remain faithful.

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

+3

All Articles