internal IEnumerator <MQMessage> DumpAllMessagesCore(bool leaveMessages) { var ibmQueue = OpenQueueCore(leaveMessages ? OpenQueueMode.ForBrowse : OpenQueueMode.ForRead); var mqGetMsgOpts = new MQGetMessageOptions(); if (leaveMessages) { mqGetMsgOpts.Options = MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_BROWSE_FIRST; } else { mqGetMsgOpts.Options = MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_SYNCPOINT; } while (true) { var msg = new MQMessage(); try { ibmQueue.Get(msg, mqGetMsgOpts); if (leaveMessages) { mqGetMsgOpts.Options = MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_BROWSE_NEXT; } } catch (MQException ex) { if (ex.ReasonCode == MQC.MQRC_NO_MSG_AVAILABLE) { break; } ibmQueue.Close(); throw; } yield return(msg); } if (!leaveMessages) { QueueManager.Commit(); } ibmQueue.Close(); }
public void ForwardMessages(IList <IMessage> messagesToForward, IQueue destinationQueue, CancellationToken ct, IProgress <int> progress = null) { if (messagesToForward == null) { throw new ArgumentNullException(nameof(messagesToForward)); } if (destinationQueue == null) { throw new ArgumentNullException(nameof(destinationQueue)); } try { var ibmQueue = OpenQueueCore(OpenQueueMode.ForRead); var destinationQ = (WsQueue)destinationQueue; var ibmQueueDest = destinationQ.OpenQueueCore(OpenQueueMode.ForWrite); var mqGetMsgOpts = new MQGetMessageOptions { Options = MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_SYNCPOINT, MatchOptions = MQC.MQMO_MATCH_MSG_ID }; var mqPutMsgOpts = new MQPutMessageOptions { Options = MQC.MQPMO_FAIL_IF_QUIESCING | MQC.MQPMO_SYNCPOINT }; int count = 0; try { foreach (var message in messagesToForward) { var retrievedMessage = new MQMessage { MessageId = message.MessageId }; try { if (progress != null && ct.IsCancellationRequested) { break; } ibmQueue.Get(retrievedMessage, mqGetMsgOpts); ibmQueueDest.Put(retrievedMessage, mqPutMsgOpts); count++; progress?.Report(count); } catch (MQException ex) { if (ex.ReasonCode == 2033 /* MQRC_NO_MSG_AVAILABLE */) { continue; } throw; } } if (QueueManager != destinationQ.QueueManager) { destinationQ.QueueManager.Commit(); } QueueManager.Commit(); } catch (Exception) { if (QueueManager != destinationQ.QueueManager) { destinationQ.QueueManager.Rollback(); } QueueManager.Rollback(); throw; } finally { ibmQueue.Close(); ibmQueueDest.Close(); RefreshInfo(); destinationQ.RefreshInfo(); } } catch (MQException ibmEx) { throw ibmEx.ToMqException(AddExtraInfoToError); } }
public void Commit(Enlistment enlistment) { QueueManager.Commit(); enlistment.Done(); }