Administration message Java™ examples 1

As this is a frequently performed process, this code example combines each step in the primeAdminMsg() method, that can be invoked in other sections of this documentation (assuming that the method has been defined for the class in question).
public class LocalQueueAdmin extends MQe
{
  public String   targetQMgr = "ExampleQM";   
// target queue manager

public MQeFields primeAdminMsg(MQeAdminMsg msg) throws Exception
{
  /*
   * Set the target queue manager that will process this message
   */
  msg.setTargetQMgr( targetQMgr );

  /*
   * Ask for a reply message to be sent to the queue 
   * manager that processes the admin request
   */
  msg.putInt  (MQe.Msg_Style,       MQe.Msg_Style_Request);
  msg.putAscii(MQe.Msg_ReplyToQ,    MQe.Admin_Reply_Queue_Name);      
  msg.putAscii(MQe.Msg_ReplyToQMgr, targetQMgr);

  /*
   * Setup the correl id so we can match the reply to the request.
   * - Use a value that is unique to the this queue manager.  
   */
  byte[] correlID = 
    Long.toHexString( (MQe.uniqueValue()).getBytes() );
  msg.putArrayOfByte( MQe.Msg_CorrelID, correlID );
       
  /*
   * Ensure matching response message is retrieved 
   * - set up a fields object that can be used as a match parameter
   *   when searching and retrieving messages.
   */
  MQeFields msgTest = new MQeFields();  
  msgTest.putArrayOfByte( MQe.Msg_CorrelID, new Byte{1, 2, 3, 4} );

  /*
   * Return the unique filter for this message
   */
  return msgTest;
}
Depending on how the destination administration queue is defined, delivery of the message can be either synchronous or asynchronous.
The next example is used to make an 'inquire all' on a queue manager. This method performs the steps required to address the admin message, request a reply, and add a unique marker to the message.
/* This method performs standard processing */
/* that primes an administration message so that */
/* we can handle it in a standard way */
/* This method sets the target queue manager */
/* (the queue manager upon which the admin */
/* action takes place. */
/* Requests that a reply message is sent to the */ 
/* admin reply queue on *the target queue manager. */ 
/* Incorporates a unique key in the message that */
/* can be used to retrieve the reply for this message.*/
/* The unique key is returned as a string,to be */
/* used by the routine extracting the reply. */

public static final String decorateAdminMsg(MQeAdminMsg msg,
                            String targetQMName)throws Exception {
    //set the target queue manager
    msg.setTargetQMgr(targetQMName);
    //indicate that we require a reply message
    msg.putInt(MQe.Msg_Style,MQe.Msg_Style_Request);
    //use default reply-to queue on the target queue manager.
    msg.putAscii(MQe.Msg_ReplyToQ,MQe.Admin_Reply_Queue_Name);
    msg.putAscii(MQe.Msg_ReplyToQMgr,targetQMName);
    //create a unique tag that we can identify the reply with
    String match ="Msg"+System.currentTimeMillis();
    msg.putArrayOfByte(MQe.Msg_CorrelID,match.getBytes());
    return match;
}

Terms of use | WebSphere software

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