Java Code to Browse MQ Messages
In order to browse messages on an MQ queue, there are two options. One, browse the messages using MQ Explorer, two use amqsbcg program from MQ_INSTALL_ROOT/bin folder. amqsbcg program takes the parameters of queue manager name and the queue name. The first option has a limitation on the message size and the second option(amqsbcg) provides the entire message but it also provides message in data bytes in numeric values for each line. That does not make it easy to read the message. Amqsbcg is a sample program compiled from amqsbcg0.c file found in MQ_INSTALL_ROOT/tools/c/samples folder. I wrote a simple java program that can browse and print messages that are easy to read.
Earlier, I discussed a java program to put a message on MQ queue. Like that one, to compile this program, you will need \Java\lib\com.ibm.mq.jar in your classpath. Compile and put this class in an appropriate jar file - I called it MQUtils.jar. You can use the following as an example to run this program:
java.exe -classpath MQ_INSTALL_ROOT\Java\lib\com.ibm.mq.jar;./MQUtils.jar com.wcsadmin.utilities.mq.PutMessage QM_Name Queue_Name
Here is the source of my program: BrowseMessages.java
Hope this helps!