I'm trying to browser messages in a queue without destroying them. I
thought the openOptions specified in the code snippet below will do the
trick but it isn't. It reads the messages just fine but it removes them
from the queue after reading them. Is there something I'm doing wrong
here? Thanks.

Taji

private static void browseQueue()
{
// create queues
MQQueue queue = null;

// Specify queue name within Queue Manager
String queueName = "LOCAL.TESTQ";

// set queue open options
int openOptions = MQC.MQOO_INPUT_SHARED |MQC.MQOO_FAIL_IF_QUIESCING |
MQC.MQGMO_BROWSE_NEXT ;

// set queue manager properties
MQEnvironment.hostname = queueHostName;
MQEnvironment.port = queuePort;
MQEnvironment.channel = queueChannelName;

try
{
// Create a connection to the queue manager
queueManager = new MQQueueManager(queueManagerName);
System.out.println("\nQueueAdapter: Connected to queue Manager " +
queueManagerName);
}
catch (MQException e)
{
System.out.println("Cannot connect to the queue manager " +
queueManagerName);
}

int messageLength = 0;
String dataString = null;

try
{
// access the queue
System.out.println("\nQueueAdapter: Trying to access queue " +
queueName);
queue = queueManager.accessQueue(queueName, openOptions, null, null,
null);
System.out.println("\nQueueAdapter: Successfully accessed queue " +
queueName);

// specify the message options
MQGetMessageOptions gmo = new MQGetMessageOptions();

// create a message object
MQMessage aMessage = new MQMessage();

byte[] msg = new byte[4096];

// keep reading the queue and write the message to standard output
System.out.println("\nMessage(s) read from queue " + queueName +
":");
while (true)
{
// set the message ID and the correlation ID
aMessage.messageId = MQC.MQMI_NONE;
aMessage.correlationId = MQC.MQCI_NONE;

// read from the queue
queue.get(aMessage, gmo);
messageLength = aMessage.getMessageLength();
aMessage.readFully(msg, 0, messageLength);

// store message read from queue in a string
dataString = new String(msg, 0, messageLength);

// write message to standard output
System.out.println(dataString);
}
}
catch (MQException mqex)
{
if (mqex.reasonCode == mqex.MQRC_NO_MSG_AVAILABLE)
{
System.out.println("QueueAdapter: No more messages available in the
queue.");
}
}
catch (Exception e)
{
System.out.println("An error occured while writing to the message
buffer : " + e.toString());
}
finally
{
try
{
// close the queue
queue.close();
}
catch (Exception qe)
{
System.out.println("Error while closing queue : " + qe.toString());
}

try
{
// disconnect from the queue manager
queueManager.disconnect();
}
catch (Exception qme)
{
System.out.println("Error while disconnecting from queue manager : "
+ qme.toString());
}
}
}