Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Advanced
Jul 25, 2005

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/bash
LD_LIBRARY_PATH=/opt/mqm/java/lib
export LD_LIBRARY_PATH
java -classpath $CLASSPATH:./com.ibm.mq.jar:/connector.jar:/jta.jar:/
com.ibm.mqbind.jar:/libmqjbnd05.so MQPutGet
Elayaraja David
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap