15 July, 2016

How to use resource adapters with JBOSS application server.

When we start using resource adapter, the first question that comes to my mind is ‘why do I need it’. Imagine, our application is a client to IBM WebSphere MQ. We can implement our application either using JMS or IBM MQ api. In some cases we are bound to use MQ apis because there are some features which are not available in JMS(like FIPS, Queue Managers etc.). If we use MQ apis then our application is tightly coupled with them.

Resource adapter enables us to export the configuration and lets us use JMS, so that it doesn’t create undue tight coupling with any proprietary apis .

Steps to configure

PART1: Server Configuration:
  • Get the resource adapter in RAR format e.g. wmq.jmsra.rar. And deploy it to the JBOSS server.
  • Standalone.xml needs to configured. Below is an example configuration
<subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
    <resource-adapters>
        <resource-adapter id="wmq.jmsra.rar">
            <archive>
                wmq.jmsra.rar
            </archive>
            <transaction-support>NoTransaction</transaction-support>
            <connection-definitions>
                <connection-definition 
                    class-name="com.ibm.mq.connector.outbound.ManagedQueueConnectionFactoryImpl" jndi-                          name="java:jboss/confac" pool-name="wmq.jmsra">
                     <config-property name="channel">
                         channel name
                     </config-property>
                     <config-property name="hostName">
                         host name or ip
                     </config-property>
                     <config-property name="transportType">
                         CLIENT
                     </config-property>
                     <config-property name="queueManager">
                         queue manager n ame
                     </config-property>
                     <config-property name="port">
                         port
                     </config-property>
                     <security>
                         <application/>
                     </security>
                 </connection-definition>
             </connection-definitions>
             <admin-objects>
                 <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/Queue" use-java-context="true" pool-name="MQ.QUEUE">
                     <config-property name="baseQueueName">
                          queue name
                     </config-property>
                     <config-property name="targetClient">
                         MQ
                     </config-property>
                 </admin-object>
             </admin-objects>
         </resource-adapter>
     </resource-adapters>
</subsystem>

PART 2: Client side configuration
3.       To configure the MDBs (for inbound connections) the following annotation can be used.
@MessageDriven( name = "ScpmsConsumerNASL",
       activationConfig = {
                                                        @ActivationConfigProperty(propertyName  = "destinationType", propertyValue = "javax.jms.Queue"),
                                                        @ActivationConfigProperty(propertyName  = "destination", propertyValue = “java:jboss/Queue”), // Ext. JNDI Name
                                                        @ActivationConfigProperty(propertyName  = "useJNDI", propertyValue = "true") // Ext. JNDI Name
                        }
)
@ResourceAdapter(value = "wmq.jmsra.rar")

I have used JNDI in my application, this can be implemented without it as well.

1 comment:

  1. very useful...
    A question, is the process same for other MoM, like Active MQ?

    ReplyDelete