import com.ibm.mq.*; //Include the WebSphere MQ classes for Java package
public class MQReceiver {
// define the name of the QueueManager
private static String qManager;
// and define the name of the Queue
private static String qName;
// main method: simply call the runReceiver() method
public static void main(String args[]) {
if (args == null || args.length != 1) {
System.out.println("needs one argument: <Queue Name>");
System.exit (0);
}
new MQReceiver().runReceiver(args);
}
public void runReceiver(String args[]) {
qName = args[0];
qManager = System.getProperty ("message.queue.manager");
try {
// Create a connection to the QueueManager
System.out.println("Connecting to queue manager: "+qManager);
MQEnvironment.channel = System.getProperty ("message.chanel.name");
MQEnvironment.hostname = System.getProperty ("message.queue.server");
MQEnvironment.port = new Integer ((System.getProperty ("message.queue.port"))).intValue();
MQEnvironment.CCSID = new Integer ((System.getProperty ("message.queue.ccsid"))).intValue();
MQQueueManager qMgr = new MQQueueManager(qManager);
// Now specify the queue that we wish to open and the open options
System.out.println("Accessing queue: "+qName);
// Now get the message back again. First define a WebSphere MQ message
// to receive the data
MQMessage rcvMessage = new MQMessage();
// Specify default get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();
// Set up the options on the queue we wish to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue queue = qMgr.accessQueue(qName, openOptions);
while (true) {
// Get the message off the queue.
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_CONVERT;
gmo.waitInterval = 15000000; // 15000 seconds
gmo.matchOptions = MQC.MQMO_NONE;