This example code is taken from the examples.application.example6 example program.
boolean msgGet = false; /* get successful? */ boolean msgConfirm = false; /* confirm successful? */ MQeMsgObject msg = null; int maxRetry = 5; /* maximum number of retries */ long confirmId = MQe.uniqueValue(); int retry = 0; while( !msgGet && retry < maxRetry) { try { msg = qmgr.getMessage( "RemoteQMgr", "RemoteQueue", filter, null, confirmId ); msgGet = true; /* get succeeded */ } catch ( Exception e ) { /* handle any exceptions */ /* if the exception is of type Except_Q_NoMatchingMsg, meaning that */ /* the message is unavailable then throw the exception */ if ( e instanceof MQeException ) if ( ((MQeException)e).code() == Except_Q_NoMatchingMsg ) throw e; retry ++; /* increment retry count */ } } if ( !msgGet ) /* was the get successful? */ /* Number of retry attempts has exceeded the maximum allowed, so abort */ /* get message operation */ return; while( !msgConfirm && retry < maxRetry ) { try { qmgr.confirmGetMessage( "RemoteQMgr", "RemoteQueue", msg.getMsgUIDFields() ); msgConfirm = true; /* confirm succeeded */ } catch ( Exception e ) { /* handle any exceptions */ retry ++; /* increment retry count */ } }