예제 #1
0
 protected override void BeforeStart(OpenedQueue queue)
 {
     foreach (var messageAction in transportActions)
     {
         messageAction.Init(this, queue);
     }
 }
예제 #2
0
 protected override void HandlePeekedMessage(OpenedQueue queue, Message message)
 {
     foreach (var action in transportActions)
     {
         if (!action.CanHandlePeekedMessage(message))
         {
             continue;
         }
         try
         {
             if (action.HandlePeekedMessage(this, queue, message))
             {
                 return;
             }
         }
         catch (Exception e)
         {
             logger.Error("Error when trying to execute action " + action + " on message " + message.Id + ". Message has been removed without handling!", e);
             queue.ConsumeMessage(message.Id);
         }
     }
     if (consumeInTransaction)
     {
         ReceiveMessageInTransaction(queue, message.Id, MessageArrived, MessageProcessingCompleted, BeforeMessageTransactionCommit, BeforeMessageTransactionRollback);
     }
     else
     {
         ReceiveMessage(queue, message.Id, MessageArrived, MessageProcessingCompleted);
     }
 }
 /// <summary>
 /// Moves the message from the timeout queue to the main queue.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="messageId">The message id.</param>
 public void MoveTimeoutToMainQueue(OpenedQueue queue, string messageId)
 {
     using (var timeoutQueue = queue.OpenSubQueue(SubQueue.Timeout, QueueAccessMode.Receive))
     {
         var message = timeoutQueue.ReceiveById(messageId);
         message.AppSpecific = 0; // reset timeout flag
         queue.Send(message);
     }
 }
예제 #4
0
        private void ReceiveMessage(OpenedQueue queue, string messageId, Func <CurrentMessageInformation, bool> messageArrived, Action <CurrentMessageInformation, Exception> messageProcessingCompleted)
        {
            var message = queue.TryGetMessageFromQueue(messageId);

            if (message == null)
            {
                return;
            }
            ProcessMessage(message, queue, null, messageArrived, null, null, messageProcessingCompleted);
        }
 public bool TryMoveMessage(OpenedQueue queue, Message message, SubQueue subQueue, out string msgId)
 {
     try
     {
         queue.MoveToSubQueue(subQueue, message);
         msgId = message.Id;
         return(true);
     }
     catch (TransportException)
     {
         msgId = null;
         return(false);
     }
 }
예제 #6
0
 private FileCurrentMessageInformation CreateMessageInformation(OpenedQueue queue, Message message, object[] messages, object msg)
 {
     return(new FileCurrentMessageInformation
     {
         MessageId = message.GetMessageId(),
         AllMessages = messages,
         Message = msg,
         Queue = queue,
         TransportMessageId = message.Id,
         Destination = Endpoint.Uri,
         Source = FileUtil.GetQueueUri(message.ResponseQueue),
         FileMessage = message,
         TransactionType = queue.GetTransactionType(),
         Headers = message.Extension.DeserializeHeaders()
     });
 }
예제 #7
0
        public void ReceiveMessageInTransaction(OpenedQueue queue, string messageId, Func <CurrentMessageInformation, bool> messageArrived, Action <CurrentMessageInformation, Exception> messageProcessingCompleted, Action <CurrentMessageInformation> beforeMessageTransactionCommit, Action <CurrentMessageInformation> beforeMessageTransactionRollback)
        {
            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = queueIsolationLevel,
                Timeout        = TransportUtil.GetTransactionTimeout(),
            };

            using (var tx = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            {
                var message = queue.TryGetMessageFromQueue(messageId);
                if (message == null)
                {
                    return; // someone else got our message, better luck next time
                }
                ProcessMessage(message, queue, tx, messageArrived, beforeMessageTransactionCommit, beforeMessageTransactionRollback, messageProcessingCompleted);
            }
        }
예제 #8
0
        public OpenedQueue Open(QueueAccessMode access, IMessageFormatter formatter)
        {
            var messageQueue = new MessageQueue(QueuePath, access);

            if (formatter != null)
            {
                messageQueue.Formatter = formatter;
            }
            var openedQueue = new OpenedQueue(this, messageQueue, QueueUri.ToString(), Transactional)
            {
                Formatter = formatter
            };

            if (SubQueue != null)
            {
                return(openedQueue.OpenSubQueue(SubQueue.Value, access));
            }
            return(openedQueue);
        }
예제 #9
0
        public void RaiseMessageSerializationException(OpenedQueue queue, Message msg, string errorMessage)
        {
            var copy = MessageSerializationException;

            if (copy == null)
            {
                return;
            }
            var messageInformation = new FileCurrentMessageInformation
            {
                FileMessage = msg,
                Queue       = queue,
                Message     = null,
                Source      = queue.RootUri,
                MessageId   = Guid.Empty
            };

            copy(messageInformation, new SerializationException(errorMessage));
        }
예제 #10
0
        private void ProcessMessage(
            Message message,
            OpenedQueue messageQueue,
            TransactionScope tx,
            Func <CurrentMessageInformation, bool> messageRecieved,
            Action <CurrentMessageInformation> beforeMessageTransactionCommit,
            Action <CurrentMessageInformation> beforeMessageTransactionRollback,
            Action <CurrentMessageInformation, Exception> messageCompleted)
        {
            Exception ex = null;

            currentMessageInformation = CreateMessageInformation(messageQueue, message, null, null);
            try
            {
                // deserialization errors do not count for module events
                var messages = DeserializeMessages(messageQueue, message, MessageSerializationException);
                try
                {
                    foreach (object msg in messages)
                    {
                        currentMessageInformation = CreateMessageInformation(messageQueue, message, messages, msg);
                        if (TransportUtil.ProcessSingleMessage(currentMessageInformation, messageRecieved) == false)
                        {
                            Discard(currentMessageInformation.Message);
                        }
                    }
                }
                catch (Exception e) { ex = e; logger.Error("Failed to process message", e); }
            }
            catch (Exception e) { ex = e; logger.Error("Failed to deserialize message", e); }
            finally
            {
                Action sendMessageBackToQueue = null;
                if (message != null && (messageQueue.IsTransactional == false || consumeInTransaction == false))
                {
                    sendMessageBackToQueue = () => messageQueue.Send(message);
                }
                var messageHandlingCompletion = new MessageHandlingCompletion(tx, sendMessageBackToQueue, ex, messageCompleted, beforeMessageTransactionCommit, beforeMessageTransactionRollback, logger, MessageProcessingFailure, currentMessageInformation);
                messageHandlingCompletion.HandleMessageCompletion();
                currentMessageInformation = null;
            }
        }
 /// <summary>
 /// Gets a listing of all timeout messages.
 /// </summary>
 /// <returns></returns>
 public IEnumerable <TimeoutInfo> GetTimeoutMessages(OpenedQueue queue)
 {
     using (var timeoutQueue = queue.OpenSubQueue(SubQueue.Timeout, QueueAccessMode.Receive))
     {
         var enumerator2 = timeoutQueue.GetMessageEnumerator2();
         while (enumerator2.MoveNext())
         {
             var message = enumerator2.Current;
             if (message == null || message.Extension.Length < 16)
             {
                 continue;
             }
             yield return(new TimeoutInfo
             {
                 Id = message.Id,
                 Time = DateTime.FromBinary(BitConverter.ToInt64(message.Extension, 16))
             });
         }
     }
 }
 protected virtual void BeforeStart(OpenedQueue queue)
 {
 }
 protected virtual void AfterStart(OpenedQueue queue)
 {
 }
 public void SendToErrorQueue(OpenedQueue queue, Message message)
 {
     queue.Send(message);
 }
예제 #15
0
 public OpenedQueue(OpenedQueue parent, MessageQueue queue, string url)
     : this(parent.info, queue, url, parent.transactional)
 {
     this.parent = parent;
 }