What are the minimum requirements for writing a Java client for MQSeries?

I need to write a simple MQSeries client in Java.

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

I've done this before a few years ago and have all the code samples, etc.

All I remember are three jar files:

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

I am doing some reading and a lot of people talk about the properties file, but I don't remember 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, but not identical with it .

+2


source to share


4 answers


The answer to the question depends on whether you want to insert the resulting code into Production. You can grab multiple jar files and include them in the CLASSPATH and make it work. In fact, with the repackaging done in version 7, the number of cans has been reduced. However, IBM does not support full client installation.

Why? A complete installation includes diagnostic tools, code support, NLS support, and the ability to collect all Must Gather information to open a fault ticket. If all you grabbed is multiple jar files, you are not getting additional features and therefore not supporting vendors if something goes wrong.

The client installation of WMQ v7 is provided as SupportPac MQC7 , which is a free download.



The jars and CLASSPATH settings for basic Java and JMS are provided in the Using Java tutorial .

Use v7 client, even on v6 server. This is backward compatibility. In version 7.0 Java / JMS everything was rewritten and you just need the jars listed in the manual.

Also, someone mentioned the jar etclient. This is an advanced transactional client and please be aware that it bears the full cost of the QMgr license. You only need this if you are doing two-phase commit (XA with WMQ and a different resource manager in the same unit of work) and not using WebSphere App Server or Message Broker. For example, you want to use TPC with JBoss, MQ and a database, you need a jclient etclient file and pay for a full WMQ license. If you are not doing XA transactions, you do not need this.

+3


source


Ok, it looks like you need the three jars I mentioned in the question and also the properties file.

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

If you don't have access to these things, the only way I could figure out to download them was to download and install the FULL trial version for MQSeries from IBM:

http://www.ibm.com/developerworks/downloads/ws/wmq/



If this link dies over time, you can also find it simply by going to www.ibm.com and then following the menu from Support & Downloads โ†’ Download โ†’ Tests and Demos and then select WebSphere MQ " from the list.

Once the installation is complete, you have all the jars you need in the java / lib folder below where the installation took place. The boxes in this version are different from the cans I mentioned above, I suspect due to differences in version.

The properties file was not installed with the installation (maybe newer versions don't need this file) but can be found here .

+1


source


Here's another way ...

Using three jar files:

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

      

Here is a sample code that will read the MQ post -

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 .

+1


source


It's been a while since I did this, IBM provides a java api to use mqseries directly and the JMS api too, which 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 configure the MQseries server, or maybe they will be kind enough to set you up for a test queue on a live server.

Anyway, when you download the MQseries server from the IBM website (trial license), which should contain the jar, you need.

I would do a lot of research on the JMS api for MQSeries, so you can stay away from using the mqseries api.

0


source







All Articles