I would use the JavaEE stack as follows:
- configure XA
DataSource for each database server - according to the user's location, the Stateless EST file looks for the corresponding DataSource and receives a connection from it.
- when translating a transaction to all servers,
Stateless EJB must iterate through all configured data sources to execute one or more queries on them, but in one transaction
In the event of a technical failure, the transaction is rolled back to all relevant servers. In the event of a business failure, the code can cause a rollback due to context.setRollbackOnly() .
This way, you first benefit from JavaEE's automated distributed transaction, and then you can use more complex templates if you need to manage the transaction manually.
BUT, the more servers you have credited to your transaction, the longer the two-phase commit operation will be, moreover, if you have a high delay between systems. And I doubt that MySQL is the best relational database to perform such complex distributed transactions.
source share