Tuesday, August 6, 2013

Using MQXAQueueConnectionFactory in Tomcat





Using Atomikos / XA transaction with your connection is not a bad idea sometimes. Below Connection Factory resource will give a nice idea about tomcat JNDI entry for
MQXAQueueConnectionFactory.
 




<Resource
                name="jms/MQCF"
                auth="Container"
                type="com.atomikos.jms.AtomikosConnectionFactoryBean"
                factory="com.atomikos.tomcat.EnhancedTomcatAtomikosBeanFactory"
                uniqueResourceName="MQPutQCFXA_MQSeries_XA_RMI"
                xaConnectionFactoryClassName="com.ibm.mq.jms.MQXAQueueConnectionFactory"
                xaProperties.hostName="YOUR_HOST"
                xaProperties.port="XXXX"
                xaProperties.channel=" CHANNEL "
                xaProperties.queueManager=" YOUR _QMGR"
                maxPoolSize="3"
                minPoolSize="1" />


I see a common exception while connecting with XA Connection factory:

Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2495;AMQ8568: The native JNI library 'mqjbnd' was not found. [3=mqjbnd]
    at com.ibm.mq.jmqi.local.LocalMQ$1.run(LocalMQ.java:252)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.ibm.mq.jmqi.local.LocalMQ.initialise_inner(LocalMQ.java:216)


This occurs when you are trying to connect to local binding. You can change that to client connection by making transport type as ‘1’.

xaProperties.transportType="1"

Just adding this property in Resource entry should resolve the issue. Please post questions if any.
I will add ActiveMQ XA Connection factory example soon.