// Receives message (first/application-specified correlationId) from status queue
        // On delete flag set to true, the method receives message without transaction context
        private Message ReceiveFromStatusQueue(long lookupId, MessageQueueTransaction transaction, MessageQueueTransactionType transactionType, bool delete)
        {
            bool transactionTypeFlag = (transactionType == MessageQueueTransactionType.Automatic) ? true : false;
            string statusQueuePath = "FormatName:DIRECT=OS:" + this.queue.MachineName + @"\" + Parameters.STATUS_QUEUE;
            MessageQueue statusQueue = new MessageQueue(statusQueuePath);
            try
            {
                bool canRead = statusQueue.CanRead;
                bool canWrite = statusQueue.CanWrite;
                if ((!canRead) || (!canWrite))
                {
                    throw new LargeMessageQueueException(null,
                        "Transactional status queue should have both read and write access for this user. Current status is: Read=" +
                        canRead + ", Write=" + canWrite);
                }
            }
            catch (MessageQueueException mqe)
            {
                throw new LargeMessageQueueException("Transactional status queue not available", mqe);
            }

            statusQueue.Formatter = new BinaryMessageFormatter();
            statusQueue.MessageReadPropertyFilter.AppSpecific = true;
            statusQueue.MessageReadPropertyFilter.CorrelationId = true;

            Message statusMessage = null;
            try
            {
                if (lookupId == 0)
                {
                    if (transactionTypeFlag)
                    {
                        statusMessage = statusQueue.ReceiveByLookupId(MessageLookupAction.First, 0, transactionType);
                    }
                    else
                    {
                        statusMessage = statusQueue.ReceiveByLookupId(MessageLookupAction.First, 0, transaction);
                    }
                }
                else
                {
                    if (delete)
                    {
                        statusMessage = statusQueue.ReceiveByLookupId(lookupId);
                    }
                    else
                    {
                        if (transactionTypeFlag)
                        {
                            statusMessage = statusQueue.ReceiveByLookupId(MessageLookupAction.Current, lookupId, transactionType);
                        }
                        else
                        {
                            statusMessage = statusQueue.ReceiveByLookupId(MessageLookupAction.Current, lookupId, transaction);
                        }
                    }
                }
            }
            catch (MessageQueueException)
            {
                // If status queue is empty, receive will throw MessageQueueException
                throw new InvalidOperationException();
            }

            statusQueue.Dispose();
            statusQueue.Close();
            return statusMessage;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Moves the <paramref name="message"/> to errors queue.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="message">The message.</param>
 public void MoveToErrorsQueue(MessageQueue queue, Message message)
 {
     using (var destinationQueue = new MessageQueue(GetErrorsQueuePath(),QueueAccessMode.Send))
     {
         destinationQueue.Send(queue.ReceiveByLookupId(message.LookupId),
                               queue.GetTransactionType());
     }
 }
        private Message ReceiveFromMsmq(MessageQueue mq, long lookupId, MessageQueueTransaction transaction, MessageQueueTransactionType transactionType)
        {
            bool transactionTypeFlag = (transactionType == MessageQueueTransactionType.Automatic) ? true : false;
            if (transactionTypeFlag)
            {
                this.message = mq.ReceiveByLookupId(MessageLookupAction.Current, lookupId, transactionType);
            }
            else
            {
                this.message = mq.ReceiveByLookupId(MessageLookupAction.Current, lookupId, transaction);
            }

            return this.message;
        }