Hazelcast XATransaction with Bitronix Transaction Manager



我正在使用Hazelcast XA Transactions进行一些测试,并且在使用Bitronix作为事务管理器时遇到问题。

我遵循了Hazelcast官方文档:

http://docs.hazelcast.org/docs/3.5/manual/html/xatransactions.html

库版本:

Hazelcast: 3.5.4

Bitronix Transaction Manager: 2.1.4

Java: 1.7

法典:

测试方法:

@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);
}

做方法:

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,在尝试登记 XA 资源transaction.enlistResource(xaResource)时抛出。

完整的堆栈跟踪:

bitronix.tm.internal.BitronixSystemException: unknown XAResource HazelcastXaResource {myCluster}, it does not belong to a registered resource

有人遇到过这个问题吗?有什么线索吗?

显然Bitronix在使用它们之前需要注册XAResources。获得HazelcastXAResource后,我在下面添加了行,它起作用了。

EhCacheXAResourceProducer.registerXAResource(xaResource.getName(), xaResource);

相关内容

  • 没有找到相关文章

最新更新