Example - Java

Example of BrowseAndLock (Java™)

The MQeMessageEnumerationMQeEnumeration object contains all the messages that match the filter supplied to the browse. MQeEnumeration can be used in the same manner as the standard Java Enumeration. You can enumerate all the browsed messages as follows:

Note: You must supply a confirmID, in case the action of locating messages fails. It must be possible to undo the location, and this action requires the confirmID.
  long confirmID = MQe.uniqueValue();
  MQeEnumeration msgEnum = qmgr.browseMessagesAndLock( null, 
                      "MyQueue", 
                      null, null,
                               confirmID, false);
  
  while( msgEnum.hasMoreElements() )
  {  
      MQeMsgObject msg = (MQeMsgObject)msgEnum.nextElement();
      System.out.println( "Message from  queue manager: " + 
                          msg.getAscii( MQe.Msg_OriginQMgr ) );
  }  

The following code performs a delete on all the messages returned in the enumeration. The message's UniqueID and lockID are used as the filter on the delete operation:

  while(msgEnum.hasMoreElements())
  {
      MQeMsgObject msg = (MQeMsgObject)
                  msgEnum.getNextMessage(null,0);
  
      processMessage(msg);

      MQeFields filter = msg.getMsgUIDFields();
      filter.putLong(MQe.Msg_LockID, 
                msgEnum.getLockId());

      qmgr.deleteMessage(null, "MyQueue", filter);
  }

Terms of use | WebSphere software

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