Пример #1
0
        /// <summary>Move the message specified by <paramref name="lookupId"/> from <paramref name="sourceQueue"/> to the <paramref name="targetQueue"/>.</summary>
        /// <remarks>
        /// Moving message is 10 to 100 times faster than sending the message to another queue.
        /// Within a transaction you cannot receive a message that you moved to a subqueue.
        /// </remarks>
        public static void MoveMessage(QueueReader sourceQueue, SubQueue targetQueue, long lookupId, QueueTransaction transaction = null)
        {
            Contract.Requires(sourceQueue != null);
            Contract.Requires(targetQueue != null);

            if (sourceQueue.IsClosed)
            {
                throw new ObjectDisposedException(nameof(sourceQueue));
            }
            if (targetQueue.IsClosed)
            {
                throw new ObjectDisposedException(nameof(targetQueue));
            }

            int    res;
            IntPtr txnHandle;

            if (transaction.TryGetHandle(out txnHandle))
            {
                res = Native.MoveMessage(sourceQueue._handle, targetQueue.MoveHandle, lookupId, txnHandle);
            }
            else
            {
                res = Native.MoveMessage(sourceQueue._handle, targetQueue.MoveHandle, lookupId, transaction.InternalTransaction);
            }

            if (Native.IsError(res))
            {
                throw new QueueException(res);
            }
        }