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.
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; }
/** *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; }