users@glassfish.java.net

_at_Resource injection for IBM MQ topic in GF V3

From: Comerford, Sean <Sean.Comerford_at_espn.com>
Date: Wed, 20 Jun 2012 21:10:11 -0400

This started out as a cry for help but I figured out the answer before completing the email :-)

Wanted to send anyway (with answer) for the next guy trying to get @Resource injection of a Websphere MQ topic working on Glassfish V3 using IBM's wmq.jmsra resource adapter.

Long story short, do NOT use the admin console to create your topic's Admin Object Resource in V3 even though that worked in V2! V3 console forces the attribute class-name="com.ibm.mq.connector.outbound.MQTopicProxy" on you which results in @Resource injection of said topic not working

Simply use asadmin create-admin-object directly so you end up with something like this in your domain.xml:

<admin-object-resource res-adapter="wmq.jmsra-7.0.1.4" res-type="javax.jms.Topic" jndi-name="jms/NBATopic">
<property name="baseTopicName" value="SA/NBA"></property>
<property name="baseQueueManagerName" value="QM_ESPN_01_DEV"></property>
</admin-object-resource>

If you use the admin console you get something like this - note the class-name attribute which results in the resource injection not working (guessing that IBM class not @Resource compliant?).

<admin-object-resource enabled="false" res-adapter="wmq.jmsra-7.0.1.4" res-type="javax.jms.Topic" description="" jndi-name="jms/NBATopic2"
class-name="com.ibm.mq.connector.outbound.MQTopicProxy">
<property name="baseTopicName" value="SA/NBA"></property>
<property name="baseQueueManagerName" value="QM_ESPN_01_DEV"></property>
</admin-object-resource>

Here's the long back story / full instructions on how to set up Glassfish to talk to Websphere MQ using the IBM RA:

 1. Install IBM RA far to GF instance (your MQ distro should come with a file named something like wmq.jmsra-7.0.1.4.rar which can be deployed directly)
 2. Create a connector connection pool specifying wmq.jmsra-7.0.1.4 as the resource adapter and javax.jms.TopicConnectionFactory as the definition (seems it has to be TopicConnectionFactory not generic ConnectionFactory). We set "NoTransaction" and then set the following properties: transportType; channel; hostName;, queueManager; port. The connection factory can be pinged successfully in both V2 and V3.
 3. Create a Connector Resource pointing to the connection pool created in step 2.
 4. Create a Connector Admin Object Resource jms/NBATopic of type javax.jms.Topic specifying the wmq.jmsra adapter and the topic + queue manager properties required by the IBM RA. NOTE*: if you try step 4 using the GF V2 admin console, all is good. If you try it using the V3 admin console, you will run into the class-name attribute problem described above and no workey – so use asadmin create-admin-object in V3!!!

Then the code to get the topic and publish to it is pretty simple and looks something like this:

    @Resource(mappedName = "jms/SPORTSQMTCF")
    private TopicConnectionFactory connectionFactory;

    @Resource(mappedName = "jms/NBATopic")
    private Topic topic;

   …

    public void send(String msg) throws Exception {
        connection = connectionFactory.createTopicConnection();
        session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        messageProducer = session.createProducer(topic);
        textMessage = session.createTextMessage();
        textMessage.setText(request.getParameter("msgText"));
        messageProducer.send(textMessage);
    }

Hope this helps someone :-)

--
Sean Comerford
ESPN.com Site Architecture