我正在使用Hazelcast XA Transactions进行一些测试,并且在使用Bitronix作为事务管理器时遇到了麻烦。
我已关注Hazelcast官方文档:
http://docs.hazelcast.org/docs/3.5/manual/html/xatransactions.html
Libs版本:
if smallest_num.is_integer():
# print as integer
print "The smallest is %d" % smallest_num
else:
# print as float
print "The smallest is %f" % smallest_num
Hazelcast: 3.5.4
Bitronix Transaction Manager: 2.1.4
代码:
测试方法:
Java: 1.7
Hazelcast实例创建方法:
@Test
public void hazelcastBitronixXATransactionTest() throws Exception{
try{
doHazelcastXATransactionTest(createInstance("myCluster"));
}catch(Exception e){
Assert.fail();
System.out.println("Other Exception:" + e.getMessage());
}
}
做法:
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);
}
我在尝试登记XA资源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();
}
}
时收到了BitronixSystemException
。
完整的堆栈跟踪:
transaction.enlistResource(xaResource)
有人遇到过这个问题吗?关于这个的任何线索?
答案 0 :(得分:1)
显然Bitronix需要在使用之前注册XAResources。
我在获得HazelcastXAResource
之后添加了以下内容,并且有效。
EhCacheXAResourceProducer.registerXAResource(xaResource.getName(), xaResource);