Wait for an administration reply message

Since administration is performed asynchronously, you will have to wait for the reply to the admin message in order to determine if the action was successful. Standard MQe message processing is used to wait for a reply or notification of a reply. In the Java™ code base, for instance, the queue manager API call waitForMessage() can be used for this purpose.

There is a time lag between sending the request and receiving the reply message. The time lag may be small if the request is being processed locally or may be long if both the request and reply messages are delivered asynchronously. The following Java code fragment could be used to send a request message and wait for a reply:
public class LocalQueueAdmin extends MQe
{
  public String   targetQMgr = "ExampleQM";  
  // target queue manager
  public int      waitFor    =   10000;      
  // millisecs to wait for reply

/*
 * Send a completed admin message.  
 *   Uses the simple putMessage method which is not assured if the 
 *   the queue is defined for synchronous operation. 
 */
public void sendRequest( MQeAdminMsg msg ) throws Exception
{
  myQM.putMessage( targetQMgr, 
                   MQe.Admin_Queue_Name, 
                   msg, 
                   null, 
                   0L );
}
/*
 * Wait ten seconds for a reply message. This method will wait for
 * a limited time on either a local or a remote reply to queue.
 *
 * 
 */
public MQeAdminMsg waitForReply(MQeFields msgTest) throws Exception {
  int secondsElapsed = 0;
  MQeAdminMsg msg = null;
  try {
    msg = (MQeAdminMsg)myQM.getMessage(
                  targetQMgr, 
                  MQe.Admin_Reply_Queue_Name, 
                  msgTest, null, 0L);
  } catch (MQeException e) {
    if (e.code() != MQe.Except_Q_NoMatchingMsg) {
      // if the exception is 'no matching 
      //message then ignore it.  This
      // will result in a null return value. 
      //Rethrow all other exceptions
      throw e;
    }
  }
  while (null == msg && secondsElapsed < 10) {
    Thread.sleep(1000);
    secondsElapsed++;
    try {
      msg = (MQeAdminMsg)myQM.getMessage(
                    targetQMgr, 
                    MQe.Admin_Reply_Queue_Name, 
                    msgTest, null, 0L);
    } catch (MQeException e) {
      if (e.code() != MQe.Except_Q_NoMatchingMsg) {
        // if the exception is 'no matching message' then ignore it. This
        // will result in a null return value. Rethrow all other exceptions
        throw e;
      }
    }
  }
  return msg;
}
This method is a simple wrapper for the MQeQueueManager API call waitForMessage(), that sets up a filter to select the required admin reply, and casts any message obtained to an admin message.
/**
*Wait for message -waits for a message to arrive on the admin reply queue
*of the specified target queue manager.Will wait only for messages with the
*specified unique tag return message,or return null if timed out */

public static final MQeAdminMsg waitForRemoteAdminReply(
                                        MQeQueueManager localQueueManager,
                                        String remoteQueueManagerName,
                                        String match)throws Exception {
    //construct a filter to ensure we only get the matching reply
    MQeFields filter =new MQeFields();
    filter.putArrayOfByte(MQe.Msg_CorrelID,match.getBytes());
    //now wait for the reply message
    MQeMsgObject reply =localQueueManager.waitForMessage(
                                               remoteQueueManagerName,
                                               MQe.Admin_Reply_Queue_Name,
                                               filter,
                                               null,
                                               0L,
                                               10000);//wait for 10 seconds
    return (MQeAdminMsg)reply;
}

Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.