Skip to main content

@Resource injection for IBM MQ topic in GF V3

Please note these forums are being decommissioned and use the new and improved forums at
5 replies [Last post]
Comerford, Sean...
Joined: 2010-11-05

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
David Zhao

Hi Sean,

By looking at the admin-object-resource nodes produced by both gui and asadmin in your domain.xml below, I suspect it may not be caused by the class-name property, but by the enabled property instead. If the admin object is created via asadmin, then there is no enabled property produced, which is true by default. If it is created via gui, then enabled="false" is added although it is displayed Enabled=true in the web page of admin gui. For an admin object which is disabled, maybe it cannot be bind to JNDI when deployment. That could be the reason why injection fails in NameNotFoundException of looking up admin object from JNDI. Could you please retry it by manually removing enabled="false" or changing it to enabled="true" in the admin-object-resource with class-name provided in domain.xml?


David Zhao

From: Comerford, Sean []
Sent: Thursday, June 21, 2012 9:10 AM
Subject: @Resource injection for IBM MQ topic in GF V3

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="" 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:

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?).

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

Install IBM RA far to GF instance (your MQ distro should come with a file named something like wmq.jmsra- which can be deployed directly)
Create a connector connection pool specifying wmq.jmsra- 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.
Create a Connector Resource pointing to the connection pool created in step 2.
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();




Hope this helps someone :-)


Sean Comerford Site Architecture

Comerford, Sean...
Joined: 2010-11-05

Comerford, Sean...
Joined: 2010-11-05

Joined: 2004-05-21

Joined: 2007-10-12