如何在 JBOSS MDB 中禁用 XA 连接
Posted
技术标签:
【中文标题】如何在 JBOSS MDB 中禁用 XA 连接【英文标题】:How to disable XA connection in JBOSS MDBs 【发布时间】:2017-01-23 07:00:51 【问题描述】:我正在使用 JBOSS EAP 6.4.2 和 IBM MQ 7.5.0.5 客户端版本。我想禁用 JBOSS 默认为 MDB 创建的 XA 连接。我正在使用 JCA 资源适配器。
1. I need to disable XA because the MQ server is HP NONStop server
v5.3.1.12 which doesn't support XA. Consequently, the following
error is coming. *javax.transaction.xa.XAException: The method
'xa_open' has failed with errorCode '-3'*
2. I've already tried changing the ra.xml
< transaction-support>XATransaction</ transaction-support >
TO
< transaction-support >LocalTransaction</ transaction-support >
without any luck.
3. Also, I've tried adding
@TransactionManagement(CONTAINER)
@TransactionAttribute(REQUIRED)
to the MBDs without any luck.
我在这里缺少什么? 请帮忙。
【问题讨论】:
您有没有偶然发现这一点?我有同样的问题,似乎找不到解决方案。 【参考方案1】:我遇到同样的问题并进行了相同的配置,但无法正常工作。连接工厂仍在内部创建 de IBM XA ConnectionFactory。我试图将 wrap-xa-resource 设置为 false,但该值没有重新定义,我不知道为什么。所以我在连接工厂上做了一个连接包装器得到了 jndi 并且它工作正常。
public class IBMMQConnectionFactoryWrapperWithoutXA implements ConnectionFactory
final ConnectionFactory originalCF;
final ConnectionFactory mqCF;
final String username;
final String password;
public IBMMQConnectionFactoryWrapperWithoutXA(ConnectionFactory originalCF) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, NoSuchMethodException, InvocationTargetException
this.originalCF = originalCF;
Field theMCFField = originalCF.getClass().getDeclaredField("theMCF");
theMCFField.setAccessible(true);
Object theMCFValue = theMCFField.get(originalCF);
Method getPasswordMethod = theMCFValue.getClass().getSuperclass().getSuperclass().getMethod("getPassword");
this.password = (String)getPasswordMethod.invoke(theMCFValue);
Field usernameField = theMCFValue.getClass().getSuperclass().getSuperclass().getDeclaredField("username");
usernameField.setAccessible(true);
this.username = (String)usernameField.get(theMCFValue);
Field theCFField = theMCFValue.getClass().getDeclaredField("theCF");
theCFField.setAccessible(true);
this.mqCF = (ConnectionFactory)theCFField.get(theMCFValue);
@Override
public Connection createConnection() throws JMSException
return this.createConnection(username, password);
@Override
public Connection createConnection(String userName, String password) throws JMSException
return this.mqCF.createConnection(userName, password);
@Override
public JMSContext createContext()
return this.createContext(username, password);
@Override
public JMSContext createContext(String userName, String password)
return this.mqCF.createContext(userName, password);
@Override
public JMSContext createContext(String userName, String password, int sessionMode)
return this.mqCF.createContext(userName, password,sessionMode);
@Override
public JMSContext createContext(int sessionMode)
return this.createContext(username, password, sessionMode);
创建一个 jmsConnectionFactoryBean:
@Bean
public ConnectionFactory jmsConnectionFactory()
JndiObjectFactoryBean jmsCF = new JndiObjectFactoryBean();
jmsCF.setResourceRef(true);
ConnectionFactory cf = jmsCF.getJndiTemplate().lookup("jms/ibmCF");
return new IBMMQConnectionFactoryWrapperWithoutXA(cf);
【讨论】:
以上是关于如何在 JBOSS MDB 中禁用 XA 连接的主要内容,如果未能解决你的问题,请参考以下文章
如何在 JBoss 5 中订购 EJB 和 JMS 队列配置的部署?
如何在 KeyCloak-Server-Distribution 中禁用 Jboss PeriodicRotatingFileHandler