The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

kalyanwsl (5) [Avatar] Offline
#1
Hi,

I am trying to implement XA transactions on JDBC Connectors. It is not working as I expected. Please see the below use case: (I referred http://blogs.mulesoft.org/how-to-work-with-jdbc-and-xa-transactions/)
1) Mule application has two JDBC Endpoints.
2) First JDBC endpoint inserts a record into a database.
3) Second JDBC endpoint inserts a record into another database.
4) Both above JDBC endpoint have to be in a XA transaction.
5) If second JDBC endpoint transaction fails, then first JDBC endpoint transaction has to be rolled back.

But in my application the first JDBC endpoint transaction is not being rolled back.

Please see below mule application configuration xml file.

===========================================
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jbossts="http://www.mulesoft.org/schema/mule/jbossts" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlnssmiliesi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd <br /> http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd <br /> http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd <br /> http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd <br /> http://www.mulesoft.org/schema/mule/jbossts http://www.mulesoft.org/schema/mule/jbossts/current/mule-jbossts.xsd <br /> http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

<spring:beans>
<spring:bean id="LocalDBBean" name="LocalDBBean" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
<spring:property name="url" value="jdbc:mysql://localhost:3306/demo"/>
<spring:property name="user" value="root"/>
</spring:bean>
<spring:bean id="RemoteDBBean" name="RemoteDBBean" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
<spring:property name="url" value="jdbc:mysql://192.168.1.55:3306/mule"/>
<spring:property name="user" value="root"/>
<spring:property name="password" value="root"/>
</spring:bean>
</spring:beans>
<jdbc-ee:connector name="LocalDBBeanConnector" dataSource-ref="LocalDBBean" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<jdbc-ee:connector name="RemoteDBBeanConnector" dataSource-ref="RemoteDBBean" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<jbossts:transaction-manager doc:name="Transaction Manager"/>
<flow name="XATransactions2Flow1" doc:name="XATransactions2Flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8085" path="insertQry" doc:name="HTTP"/>
<eesmiliea-transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insertQry" queryTimeout="-1" connector-ref="RemoteDBBeanConnector" doc:name="RemoteDatabaseEndpoint">
<xa-transaction action="ALWAYS_BEGIN"/>
<jdbc-ee:query key="insertQry" value="insert into test (name) values ('test2A')"/>
</jdbc-ee:outbound-endpoint>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insertQry" queryTimeout="-1" connector-ref="LocalDBBeanConnector" doc:name="LocalDatabaseEndpoint">
<xa-transaction action="ALWAYS_JOIN"/>
<jdbc-ee:query key="insertQry" value="insert into demo1 (name) values ('test2')"/>
</jdbc-ee:outbound-endpoint>
<rollback-exception-strategy doc:name="Rollback Exception Strategy"/>
</eesmiliea-transactional>
</flow>
</mule>

===========================================

Did I miss any other configurations for XA Transactions? Could you please direct me to best practice documentation.

Thanks,
Kalyan
David Dossot (233) [Avatar] Offline
#2
Re: Unable to implement XA transactions using JDBC connectors
The first JDBC endpoint should use ALWAYS_JOIN to join the transaction started by eesmiliea-transactional.
kalyanwsl (5) [Avatar] Offline
#3
Re: Unable to implement XA transactions using JDBC connectors
Thanks alot David,

It worked for me.