I'm making some tests with Hazelcast XA Transactions and I'm having trouble when using Bitronix as the Transaction Manager.
I have followed Hazelcast official documentation:
http://docs.hazelcast.org/docs/3.5/manual/html/xatransactions.html
Libs versions:
Hazelcast: 3.5.4
Bitronix Transaction Manager: 2.1.4
Java: 1.7
Code:
Test method:
@Test
public void hazelcastBitronixXATransactionTest() throws Exception{
try{
doHazelcastXATransactionTest(createInstance("myCluster"));
}catch(Exception e){
Assert.fail();
System.out.println("Other Exception:" + e.getMessage());
}
}
Hazelcast instance creation method:
private HazelcastInstance createInstance(String clusterName){
System.setProperty("hazelcast.logging.type", "slf4j");
Config config = new Config();
config.getGroupConfig().setName(clusterName);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
tcpIpConfig.setEnabled(false);
return Hazelcast.newHazelcastInstance(config);
}
Do method:
private void doHazelcastXATransactionTest(HazelcastInstance hazelcastInstance) throws Exception{
BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager();
btm.setTransactionTimeout(60);
btm.begin();
HazelcastXAResource xaResource = hazelcastInstance.getXAResource();
Transaction transaction = btm.getTransaction();
transaction.enlistResource(xaResource);
try {
TransactionContext context = xaResource.getTransactionContext();
TransactionalMap map = context.getMap("m");
map.put("key", "value");
transaction.delistResource(xaResource, XAResource.TMSUCCESS);
btm.commit();
} catch (Exception e) {
System.out.println("Exception do rollback:" + e.getMessage());
btm.rollback();
}
}
I'm receiving a BitronixSystemException
, thrown when trying to enlist the XA resource transaction.enlistResource(xaResource)
.
The complete stacktrace:
bitronix.tm.internal.BitronixSystemException: unknown XAResource HazelcastXaResource {myCluster}, it does not belong to a registered resource
Someone has faced this issue? Any clues on this?