How to configure IBM MQ Resource Adapter on WildFly

This guide will take through the steps required to install IBM MQ Resource Adapter on WildFly and verify the installation with a Docker Image of IBM MQ.

To get started, the first thing which is required is the IBM MQ Resource Adapter which can be downloaded from IBM site (you need to register on IBM site to be able to download it).

Here are the steps to Download IBM MQ Resource Adapter:

  1. Go to Fix Central (https://www.ibm.com/support/fixcentral/)
  2. Next, in the Product Selector field enter “WebSphere MQ” and select it from the list.
  3. Then, from the “Installed Version” field select the latest version..
  4. Next, in the “Platform” field select your platform or just choose “All”, then press Continue.
  5. On the next page select the “Browse for Fixes” button and make sure that the “Show fixes that apply to this version” button is also selected, then press Continue.
  6. Select the WS-MQ-Java-InstallRA version you want and download it

Finally, copy the file wmq.jmsra.rar file into the deployments directory of WildFly (f.e. $JBOSS_HOME/standalone/deployments).

Start IBM MQ

The simplest way to start IBM MQ is by means of Docker. You can pull and start the latest version of IBM MQ as follows:

docker run \
  --env LICENSE=accept \
  --env MQ_QMGR_NAME=QM1 \
  --publish 1414:1414 \
  --publish 9443:9443 \
  --detach \
  --volume qm1data:/mnt/mqm \
  ibmcom/mq

The above command creates and starts a Queue Manager called QM1, and maps port 1414 on the host to the MQ listener on port 1414 inside the container, as well as port 9443 on the host to the web console on port 9443 inside the container:

Update WildFly configuration

Next, update the configuration in your WildFly profile to include a reference to the resource adapter wmq.jmsra.rar:

<subsystem xmlns="urn:jboss:domain:resource-adapters:5.0">
    <resource-adapters>
        <resource-adapter id="wmq.jmsra">
            <archive>
                wmq.jmsra.rar
            </archive>
            <transaction-support>NoTransaction</transaction-support>
            <connection-definitions>
                <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl"
                                       jndi-name="java:jboss/jms/ivt/IVTCF" enabled="true" use-java-context="true"
                                       pool-name="IVTCF">
                    <config-property name="channel">SYSTEM.DEF.SVRCONN
                    </config-property>
                    <config-property
                                     name="hostName">localhost
                    </config-property>
                    <config-property name="transportType">
                        CLIENT
                    </config-property>
                    <config-property name="queueManager">
                        QM1
                    </config-property>
                    <config-property name="port">
                        1414
                    </config-property>
                </connection-definition>
                <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl"
                                       jndi-name="java:jboss/jms/ivt/JMS2CF" enabled="true" use-java-context="true"
                                       pool-name="JMS2CF">
                    <config-property name="channel">
                        SYSTEM.DEF.SVRCONN
                    </config-property>
                    <config-property name="hostName">
                        localhost
                    </config-property>
                    <config-property name="transportType">
                        CLIENT
                    </config-property>
                    <config-property name="queueManager">
                        QM1
                    </config-property>
                    <config-property name="port">
                        1414
                    </config-property>
                </connection-definition>
            </connection-definitions>
        <admin-objects>
            <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy"
                          jndi-name="java:jboss/jms/ivt/IVTQueue" pool-name="IVTQueue">
                <config-property name="baseQueueName">
                    EXAMPLE.QUEUE
                </config-property>
                </admin-object>
            </admin-objects>
        </resource-adapter>
    </resource-adapters>
</subsystem>

Within this configuration, we have exposed as admin object the Queue named EXAMPLE.QUEUE which is bound to the JNDI name jndi-name=”java:jboss/jms/ivt/IVTQueue”.

Now start WildFly and verify that the AdminObject and ConnectionFactory are registered:

2021-05-10 15:12:46,610 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-6) WFLYJCA0002: Bound JCA AdminObject [java:jboss/jms/ivt/IVTQueue]
2021-05-10 15:12:46,610 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-6) WFLYJCA0002: Bound JCA ConnectionFactory [java:jboss/jms/ivt/IVTCF]
2021-05-10 15:12:46,610 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-6) WFLYJCA0002: Bound JCA ConnectionFactory [java:jboss/jms/ivt/JMS2CF]

Depending on your WildFly version, you might find some WARN messages in the server logs:

WARN  [org.jboss.as.connector.deployers.RADeployer] (MSC service thread 1-5) IJ020017: Invalid archive: wmq.jmsra

Description: Invalid config-property-type for ManagedConnectionFactory.
Code: Class: com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl Property: CCSID Type: int

Severity: WARNING
Section: 20.7
Description: Invalid config-property-type for ManagedConnectionFactory.
Code: Class: com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl Property: sslResetCount Type: int

Severity: WARNING
Section: 20.7
Description: Invalid config-property-type for ResourceAdapter.
Code: Class: com.ibm.mq.connector.ResourceAdapterImpl Property: connectionConcurrency Type: int

These WARN messages are harmless and raised by automatic conversion of primitive int types to object types from/to the Resource Adapter.

Configuring MDB to Consume Messages from IBM MQ

Once that you have completed the Resource Adapter configuration, you can use the Admin Objects (Connection Factories, Destinations) in your MDB. Just provide the Resource Adapter name and refer to the Admin objects JNDI Name as in this example:

@MessageDriven(name="IbmMqMdb", activationConfig = {
        @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "java:jboss/jms/ivt/IVTCF"),
        @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "java:jboss/jms/ivt/IVTQueue"),
        @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue")
})
@ResourceAdapter(value = "wmq.jmsra.rar")
public class IBMMDB implements MessageListener {
    @Override
    public void onMessage(Message message) {
       ...
    }
}
Found the article helpful? if so please follow us on Socials