Hi Friends,
Forgive me for asking a basic thing, can anyone give me JAVA sample code to browse message on a given queue. I have WebSphere MQ 5.3 installed on windows but could not run even a single java program. All the time I tried to run one mqbrowse.java and get error like
Exception in thread "main" java.lang.UnsatisfiedLinkError: no mqjbnd04 in java.library.path - that seems to be as if code is campatible with MQ 5.2 version. Code is pasted below :
import com.ibm.mq.*; // Include the MQ package
import java.io.*;
import java.lang.*;
public class Mqbrowse {
private MQQueueManager qMgr;
public static void main (String args[]) throws IOException {
/****************************************************************/
/* Check to make sure that at least the queue name was entered. */
/****************************************************************/
/* Note: By passing in command line arguments in this fashion, */
/* this program strays from the 100% Pure Java philosophy (not */
/* all OSs allow for arguments). However, the purpose of this */
/* program is to show the use of the MQSeries browsing not the */
/* use of Java argument passing. */
/****************************************************************/
if (args.length < 1) {
System.out.println("Required parameter missing - queue name"
} else {
System.out.println("mqbrowse: browse and optionally get messages"
Mqbrowse mySample = new Mqbrowse();
mySample.init();
mySample.start(args);
}
System.exit(0);
}
/**********************************************************/
/* This program doesn't have any specific initialization. */
/* If it did, it could go here. */
/**********************************************************/
public void init() {
}
public void start(String args[]) {
try {
/******************************************************/
/* Create a queue manager object and access the queue */
/* that will be used for the putting of messages. */
/******************************************************/
if (args.length > 1) {
qMgr = new MQQueueManager(args[1]);
} else {
qMgr = new MQQueueManager(""
}
int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;
MQQueue myQueue = qMgr.accessQueue(args[0], openOptions,
null, null, null);
/*****************************************/
/* Set up a reader to get the user input */
/*****************************************/
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String runShow;
/******************************************************/
/* Set up our options to browse for the first message */
/******************************************************/
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
MQMessage myMessage = new MQMessage();
/***************************/
/* Set up a loop exit flag */
/***************************/
boolean done = false;
do {
try {
/*****************************************/
/* Reset the message and IDs to be empty */
/*****************************************/
myMessage.clearMessage();
myMessage.correlationId = MQC.MQCI_NONE;
myMessage.messageId = MQC.MQMI_NONE;
/**************************************************/
/* Browse the message, display it, and ask if the */
/* message should actually be gotten */
/**************************************************/
myQueue.get(myMessage, gmo);
String msg = myMessage.readString(myMessage.getMessageLength());
System.out.println("Browsed message: " + msg);
System.out.println("Actually get message?"
runShow = br.readLine();
if (runShow.length() > 0) {
if ( (runShow.indexOf("Y" != -1)
|| (runShow.indexOf("y" != -1) ) {
System.out.println("Actually getting the message"
gmo.options = MQC.MQGMO_MSG_UNDER_CURSOR;
myQueue.get(myMessage, gmo);
}
}
/************************************************/
/* Reset the options to browse the next message */
/************************************************/
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
} catch (MQException ex) {
/**************************************************/
/* Probably encountered our no message available: */
/* write out error and mark loop to be exited */
/**************************************************/
System.out.println("MQ exception: CC = " + ex.completionCode
+ " RC = " + ex.reasonCode);
done = true;
} catch (java.io.IOException ex) {
System.out.println("Java exception: " + ex);
done = true;
}
} while (!done);
/**********************************************************/
/* Before the program ends, the open queue will be closed */
/* and the queue manager will be disconnected. */
/**********************************************************/
myQueue.close();
qMgr.disconnect();
}
catch (MQException ex) {
System.out.println("MQ exception: CC = " + ex.completionCode
+ " RC = " + ex.reasonCode);
}
}
}
Forgive me for asking a basic thing, can anyone give me JAVA sample code to browse message on a given queue. I have WebSphere MQ 5.3 installed on windows but could not run even a single java program. All the time I tried to run one mqbrowse.java and get error like
Exception in thread "main" java.lang.UnsatisfiedLinkError: no mqjbnd04 in java.library.path - that seems to be as if code is campatible with MQ 5.2 version. Code is pasted below :
import com.ibm.mq.*; // Include the MQ package
import java.io.*;
import java.lang.*;
public class Mqbrowse {
private MQQueueManager qMgr;
public static void main (String args[]) throws IOException {
/****************************************************************/
/* Check to make sure that at least the queue name was entered. */
/****************************************************************/
/* Note: By passing in command line arguments in this fashion, */
/* this program strays from the 100% Pure Java philosophy (not */
/* all OSs allow for arguments). However, the purpose of this */
/* program is to show the use of the MQSeries browsing not the */
/* use of Java argument passing. */
/****************************************************************/
if (args.length < 1) {
System.out.println("Required parameter missing - queue name"
} else {
System.out.println("mqbrowse: browse and optionally get messages"
Mqbrowse mySample = new Mqbrowse();
mySample.init();
mySample.start(args);
}
System.exit(0);
}
/**********************************************************/
/* This program doesn't have any specific initialization. */
/* If it did, it could go here. */
/**********************************************************/
public void init() {
}
public void start(String args[]) {
try {
/******************************************************/
/* Create a queue manager object and access the queue */
/* that will be used for the putting of messages. */
/******************************************************/
if (args.length > 1) {
qMgr = new MQQueueManager(args[1]);
} else {
qMgr = new MQQueueManager(""
}
int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;
MQQueue myQueue = qMgr.accessQueue(args[0], openOptions,
null, null, null);
/*****************************************/
/* Set up a reader to get the user input */
/*****************************************/
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String runShow;
/******************************************************/
/* Set up our options to browse for the first message */
/******************************************************/
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
MQMessage myMessage = new MQMessage();
/***************************/
/* Set up a loop exit flag */
/***************************/
boolean done = false;
do {
try {
/*****************************************/
/* Reset the message and IDs to be empty */
/*****************************************/
myMessage.clearMessage();
myMessage.correlationId = MQC.MQCI_NONE;
myMessage.messageId = MQC.MQMI_NONE;
/**************************************************/
/* Browse the message, display it, and ask if the */
/* message should actually be gotten */
/**************************************************/
myQueue.get(myMessage, gmo);
String msg = myMessage.readString(myMessage.getMessageLength());
System.out.println("Browsed message: " + msg);
System.out.println("Actually get message?"
runShow = br.readLine();
if (runShow.length() > 0) {
if ( (runShow.indexOf("Y" != -1)
|| (runShow.indexOf("y" != -1) ) {
System.out.println("Actually getting the message"
gmo.options = MQC.MQGMO_MSG_UNDER_CURSOR;
myQueue.get(myMessage, gmo);
}
}
/************************************************/
/* Reset the options to browse the next message */
/************************************************/
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
} catch (MQException ex) {
/**************************************************/
/* Probably encountered our no message available: */
/* write out error and mark loop to be exited */
/**************************************************/
System.out.println("MQ exception: CC = " + ex.completionCode
+ " RC = " + ex.reasonCode);
done = true;
} catch (java.io.IOException ex) {
System.out.println("Java exception: " + ex);
done = true;
}
} while (!done);
/**********************************************************/
/* Before the program ends, the open queue will be closed */
/* and the queue manager will be disconnected. */
/**********************************************************/
myQueue.close();
qMgr.disconnect();
}
catch (MQException ex) {
System.out.println("MQ exception: CC = " + ex.completionCode
+ " RC = " + ex.reasonCode);
}
}
}