Websphere MQ Everyplace

examples.queuemanager
Class MessageWaiter

java.lang.Object
  |
  +--examples.queuemanager.MessageWaiter

public class MessageWaiter
extends java.lang.Object

This class illustrates how to wait for a message to appear on a particular queue. It is intended as an example that can be modified to suit an individual developers requirements, rather than a reusable code snippet.

Note that although this method will wait for a message on a local queue residing upon a remote queue manager, it will do so by polling across the network. It will also require that the correct connection definitions are set up, and that the remote queue manager is responding.


Field Summary
static short[] version
           
 
Constructor Summary
MessageWaiter(MQeQueueManager queueManager, java.lang.String queueQueueManagerName, java.lang.String queueName)
          Create a message waiter on a specified queue.
 
Method Summary
 MQeMsgObject getMessage(MQeFields filter)
          Get a message from the receivers queue.
 MQeMsgObject waitForMessage(MQeFields filter, long totalWaitTime, long waitGranularity)
          Wait for a message on the receivers queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static short[] version
Constructor Detail

MessageWaiter

public MessageWaiter(MQeQueueManager queueManager,
                     java.lang.String queueQueueManagerName,
                     java.lang.String queueName)
Create a message waiter on a specified queue. Caching these values reduces the number of parameters passed to waitForMessage

Parameters:
queueManager - The queue manager instance used as an access point to the MQe system.
queueQueueManagerName - The name of the queue manager upon which the local queue resides.
queueName - The name of the queue manager upon which the desired message resides.
Method Detail

getMessage

public final MQeMsgObject getMessage(MQeFields filter)
                              throws java.lang.Exception
Get a message from the receivers queue. The message returned will have been remove from the queue. If the message is not on the queue return null (instead of throwing an exception) this makes control more simple at the next level; All other exceptions thrown by the MQeQueueManager.getMessage() call are propagated up the stack to the caller.

To ignore a particular exception and keep retrying, catch the exception in this method and do not propagate it up the stack. The original implementation of MQeQueueManager.waitForMessage() can be duplicated by catching ALL exceptions and propagating none.

Parameters:
filter - (com.ibm.mqe.MQeFields) a matching criteria for the message. May be null;
Returns:
MQeMsgObject object.
Throws:
java.lang.Exception

waitForMessage

public final MQeMsgObject waitForMessage(MQeFields filter,
                                         long totalWaitTime,
                                         long waitGranularity)
                                  throws java.lang.Exception
Wait for a message on the receivers queue. The message returned will have been remove from the queue. If no message is found within the specified time then null will be returned.

Any exception thrown while retreiving the message (except for message not found) will be thrown to the caller. This is not exactly the behaviour exhibited by the deprecated MQeQueueManager.waitForMessage(), which would continue trying until the time elapsed or a message was retreived. The original behaviour can be recreated by masking ALL exceptions in the MessageWaiter.getMessage() method.

Parameters:
filter - a matching criteria for the message. May be null
totalWaitTime - the maximum amount of time to wait for a message.
Returns:
MQeMsgObject the message we were waiting for or null it none received.
Throws:
java.lang.Exception

Websphere MQ Everyplace