dcsimg
LinkedIn
Google+
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
Thanks for your registration, follow us on our social networks to keep up-to-date