private Message ReceiveMessageByCorrelationId(System.Messaging.MessageQueue queue, string correlationId)
        {
            var messageQueueTransaction = new System.Messaging.MessageQueueTransaction();

            messageQueueTransaction.Begin();

            var message = _messageQueueManager.ReceiveByCorrelationId(queue, correlationId, TimeSpan.FromMilliseconds(0), messageQueueTransaction);

            messageQueueTransaction.Commit();

            return(message);
        }
Ejemplo n.º 2
0
        private ITransactionalMessage ReceiveMessage()
        {
            var messageQueueTransaction = CreateTransaction();

            messageQueueTransaction?.Begin();

            try
            {
                using (var memoryStream = new MemoryStream())
                {
                    var message = MessageQueueManager.Receive(MessageQueue, TimeSpan.Zero, messageQueueTransaction?.Transaction);

                    if (message == null)
                    {
                        Logger.Debug($"Receive timeout from {Name}");
                    }
                    else
                    {
                        Logger.Debug("Received message chunk ({Chunk}/{NumberOfChunks}) from {QueueName}", 1, message.AppSpecific, Name);
                    }

                    var messageNumber = 0;

                    while (message != null && ++messageNumber <= message.AppSpecific)
                    {
                        message.BodyStream.CopyTo(memoryStream);

                        if (messageNumber < message.AppSpecific)
                        {
                            message = MessageQueueManager.ReceiveByCorrelationId(MessageQueue, message.Id, TimeSpan.Zero, messageQueueTransaction?.Transaction);

                            if (message == null)
                            {
                                throw new MissingChunkException(Name, messageNumber);
                            }
                        }
                    }

                    return(CreateTransactionalMessage(memoryStream, messageQueueTransaction));
                }
            }
            catch (Exception)
            {
                messageQueueTransaction?.Abort();
                messageQueueTransaction?.Dispose();

                throw;
            }
        }