devxlogo

Manage Messages from MQ Server with MQ Java Classes

Manage Messages from MQ Server with MQ Java Classes

import com.ibm.mq.*;     public class MQPutGet{  private String qManager = "QMGRname";  private String qName = "QUEUEname";  private MQQueueManager qMgr;  // define a queue manager object    public static void main(String args[]) {                  new MQPutGet();  }  public MQPutGet() {   try {      // Create a connection to the queue manager      qMgr = new MQQueueManager(qManager);      // the options on the queue       int openOptions =  MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_INQUIRE |  MQC.MQOO_OUTPUT ;            // specify the queue       MQQueue queue =     qMgr.accessQueue(qname,                               openOptions,null,                                          null,                                          null);                // Define a simple message, and write some text in UTF format:          MQMessage hello_world = new MQMessage();     hello_world.writeUTF(msg);     // specify the message options...      MQPutMessageOptions pmo = new MQPutMessageOptions();      // accept       // put the message on the queue      queue.put(hello_world,pmo);            // Set the get message options...      MQMessage retrievedMessage retrievedMessage = new MQMessage();      // Set the get message options...      MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults      queue.get(retrievedMessage, gmo);           // Close the queue...      queue.close();      // Disconnect from the queue manager      qMgr.disconnect();    }    catch (Exception ex)    {      System.out.println("An error occurred whilst writing to the message buffer: " + ex);    }  }} // end of sample

To execute the above program, set the classpath, set the following commands in a shell script, and execute it

####!/usr/local/bin/bashLD_LIBRARY_PATH=/opt/mqm/java/libexport LD_LIBRARY_PATHjava -classpath $CLASSPATH:./com.ibm.mq.jar:/connector.jar:/jta.jar:/com.ibm.mqbind.jar:/libmqjbnd05.so MQPutGet
See also  How to Avoid Money Transfer Scams  
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist