This example is taken from the examples.application.example6 example application:
boolean msgPut = false; /* put successful? */ boolean msgConfirm = false; /* confirm successful? */ int maxRetry = 5; /* maximum number of retries */ long confirmId = MQe.uniqueValue(); int retry = 0; while( !msgPut && retry < maxRetry ) { try { qmgr.putMessage( "RemoteQMgr", "RemoteQueue", msg, null, confirmId ); msgPut = true; /* message put successful */ } catch( Exception e ) { /* handle any exceptions */ /* set resend flag for retransmission of message */ msg.putBoolean( MQe.Msg_Resend, true ); retry ++; } } if ( !msgPut ) /* was put message successful?*/ /* Number of retries has exceeded the maximum allowed, /*so abort the put*/ /* message attempt */ return; retry = 0; while( !msgConfirm && retry < maxRetry ) { try { qmgr.confirmPutMessage( "RenoteQMgr", "RemoteQueue", msg.getMsgUIDFields()); msgConfirm = true; /* message confirm successful*/ } catch ( Exception e ) { /* handle any exceptions*/ /* An Except_NotFound exception means */ /*that the message has already */ /* been confirmed */ if ( e instanceof MQeException && ((MQeException)e).code() == Except_NotFound ) putConfirmed = true; /* confirm successful */ /* another type of exception - need to reconfirm message */ retry ++; } }