Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic mqbrowse program

Status
Not open for further replies.

akshukla

Technical User
Apr 30, 2003
6
JP
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(&quot;Required parameter missing - queue name&quot;);
} else {
System.out.println(&quot;mqbrowse: browse and optionally get messages&quot;);
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(&quot;&quot;);
}
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(&quot;Browsed message: &quot; + msg);
System.out.println(&quot;Actually get message?&quot;);
runShow = br.readLine();
if (runShow.length() > 0) {
if ( (runShow.indexOf(&quot;Y&quot;) != -1)
|| (runShow.indexOf(&quot;y&quot;) != -1) ) {
System.out.println(&quot;Actually getting the message&quot;);
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(&quot;MQ exception: CC = &quot; + ex.completionCode
+ &quot; RC = &quot; + ex.reasonCode);
done = true;
} catch (java.io.IOException ex) {
System.out.println(&quot;Java exception: &quot; + 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(&quot;MQ exception: CC = &quot; + ex.completionCode
+ &quot; RC = &quot; + ex.reasonCode);
}
}

}


 
Whenver you get an exception such as this one, Exception in thread &quot;main&quot; java.lang.UnsatisfiedLinkError: no mqjbnd04 in java.library.path , you should check to see if your classpath is set appropriately and you are having the right jar files in there.

As for a java sample, i think you do have some in the app programming guide manual.



Cheers
KK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top