views:

644

answers:

4

I need to write a simple MQSeries client in Java.

The client just has to connect to the queue and pull off the next message.

I have done this before a number of years ago and have all the sample code etc.

All I remember needing are the three jar files:

  • com.ibm.mq.iiop.jar
  • com.ibm.mq.jar
  • connector.jar

I have been doing some reading and a lot of people talk about a properties file, but I have no recollection of this from my past experience.

And so on to my question:

What is the absolute minimum I need on my system to develop, test and ultimately deploy a simple MQSeries client?

And where can I find (download) these things?

NOTE: This question is related to but not the same as this one.

A: 

Hi, Its been a while since I did this too, IBM provides java api for directly using mqseries and JMS api too that is a wrapper around it.

Go here, they have many examples in java http://www304.ibm.com/jct01005c/isv/tech/sampmq.html

For testing, you will need to download and setup a MQseries Server, or maybe they will be kind enough to set you up with a test queue on the real server.

In anycase, when you download the MQseries server from the IBM's website (trial lic) that should contain the jar's you need.

I would strongly research into the JMS api for MQSeries, so that you can stay away from actually using the mqseries api.

Devender Gollapally
Your link seems to be broken.
Ron Tuffin
sorry here it ishttp://www-304.ibm.com/jct01005c/isv/tech/sampmq.html
Devender Gollapally
A: 

Ok it looks like you need the three jars I mentioned in the question as well as a properties file.

  • com.ibm.mq.iiop.jar
  • com.ibm.mq.jar
  • connector.jar
  • mqji.properties

Unless you have access to these things already the only way I could figure out to get them was to download and install the FULL trial version for MQSeries from IBM:

http://www14.software.ibm.com/webapp/download/search.jsp?pn=WebSphere+MQ

If that link dies over time I found it by just going to www.ibm.com and then following the menu from "Support & Downloads" -> "Download" -> "Trials and demos" and then choosing "WebSphere MQ" from the list.

Once the install is done, you have all the jars you need in the java/lib folder below where the installation happened. The Jars in this version are different o the jars I mention above I suspect because of version differences.

The properties file was not installed with the install (perhaps the new versions does not need this file), but it can be found here.

Ron Tuffin
+1  A: 

Here is another way...

Using the three jar files:

com.ibm.mq.jar
com.ibm.mqetclient.jar
com.ibm.mqjms.jar

Here is a code sample that will read an MQ message -

import com.ibm.mq.*;            // Include the WebSphere MQ classes for Java package

public class MQSample
{
  private String qManager = "your_Q_manager";  // define name of queue
                                               // manager to connect to.
  private MQQueueManager qMgr;                 // define a queue manager
                                               // object
  public static void main(String args[]) {
     new MQSample();
  }

  public MQSample() {
   try {

      // Create a connection to the queue manager
      qMgr = new MQQueueManager(qManager);

      // Set up the options on the queue we wish to open...
      // Note. All WebSphere MQ Options are prefixed with MQC in Java.
      int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |
                        MQC.MQOO_OUTPUT ;

      // Now specify the queue that we wish to open,
      // and the open options...
      MQQueue system_default_local_queue =
              qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",
                               openOptions);

      // Define a WebSphere MQ message buffer to receive the message into..
      MQMessage retrievedMessage = new MQMessage();

      // Set the get message options...
      MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults
                                                           // same as  MQGMO_DEFAULT
      // get the message off the queue...
      system_default_local_queue.get(retrievedMessage, gmo);

      // And prove we have the message by displaying the UTF message text
      String msgText = retrievedMessage.readUTF();
      System.out.println("The message is: " + msgText);
      // Close the queue...
      system_default_local_queue.close();
      // Disconnect from the queue manager

      qMgr.disconnect();
    }
      // If an error has occurred in the above, try to identify what went wrong
      // Was it a WebSphere MQ error?
    catch (MQException ex)
    {
      System.out.println("A WebSphere MQ error occurred : Completion code " +
                         ex.completionCode + " Reason code " + ex.reasonCode);
    }
      // Was it a Java buffer space error?
    catch (java.io.IOException ex)
    {
      System.out.println("An error occurred whilst writing to the message buffer: " + ex);
    }
  }
} // end of sample

Code taken from this SO answer.

Mr Jacques
+1  A: 

Download the free WMQ v7 client install here:

http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24019253&loc=en%5FUS&cs=utf-8&lang=en

From there you can get the jars you need. What jars are those? Please refer to this page:

//publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzaw.doc/uj10330_.htm

...for details. (Add the http back in the URL. This site doesn't allow me to post more than one link yet.) Note there are two tables, one for plain Java and one for JMS.

Use the v7 client, even on a v6 server. It's backward compatible. In v7.0 the Java/JMS has all been rewritten and you just need the jars listed in the manual.

If you don't want to use v7 for some reason, look for the Using Java manual for the version of jars you want here:

//www-01.ibm.com/software/integration/wmq/library/

You can get v6.0 or v5.x manuals at that link.

Also, someone listed the etclient jar. That's the Extended Transactional Client and it incurs the full license cost of a QMgr. You only need it if you are doing 2-phase commit (XA with WMQ and another resource manager in the same unit of work) and not using WebSphere App Server or Message Broker. For example, you want to do TPC using JBoss, MQ and a database, you need etclient jar file and pay for a full WMQ license. If you are not doing XA transactions with WMQ and another resource manager, you don't need it.

T.Rob