Exemplo n.º 1
0
        void ProcessMessage(TransportMessage message)
        {
            if (string.IsNullOrWhiteSpace(message.Id))
            {
                Logger.Error("Message without message id detected");

                FailureManager.SerializationFailedForMessage(message, new SerializationException("Message without message id received."));

                return;
            }

            var exceptionFromStartedMessageHandling = OnStartedMessageProcessing(message);

            if (TransactionSettings.IsTransactional)
            {
                if (firstLevelRetries.HasMaxRetriesForMessageBeenReached(message))
                {
                    OnFinishedMessageProcessing(message);
                    return;
                }
            }

            if (exceptionFromStartedMessageHandling != null)
            {
                throw exceptionFromStartedMessageHandling; //cause rollback
            }
            //care about failures here
            var exceptionFromMessageHandling = OnTransportMessageReceived(message);

            //and here
            var exceptionFromMessageModules = OnFinishedMessageProcessing(message);

            //but need to abort takes precedence - failures aren't counted here,
            //so messages aren't moved to the error queue.
            if (needToAbort)
            {
                return;
            }

            if (exceptionFromMessageHandling != null)
            {
                if (exceptionFromMessageHandling is AggregateException)
                {
                    var serializationException = exceptionFromMessageHandling.GetBaseException() as  SerializationException;
                    if (serializationException != null)
                    {
                        Logger.Error("Failed to serialize message with ID: " + message.Id, serializationException);

                        message.RevertToOriginalBodyIfNeeded();

                        FailureManager.SerializationFailedForMessage(message, serializationException);
                    }
                    else
                    {
                        throw exceptionFromMessageHandling;//cause rollback
                    }
                }
                else
                {
                    throw exceptionFromMessageHandling;//cause rollback
                }
            }

            if (exceptionFromMessageModules != null) //cause rollback
            {
                throw exceptionFromMessageModules;
            }
        }
Exemplo n.º 2
0
        void ProcessMessage(TransportMessage message)
        {
            try
            {
                OnStartedMessageProcessing(message);
            }
            catch (Exception exception)
            {
                Logger.Error("Failed raising 'started message processing' event.", exception);
                if (ShouldExitBecauseOfRetries(message))
                {
                    return;
                }
                throw;
            }

            if (string.IsNullOrWhiteSpace(message.Id))
            {
                Logger.Error("Message without message id detected");

                FailureManager.SerializationFailedForMessage(message,
                                                             new SerializationException("Message without message id received."));

                return;
            }


            if (ShouldExitBecauseOfRetries(message))
            {
                try
                {
                    OnFinishedMessageProcessing(message);
                }
                catch (Exception exception)
                {
                    Logger.Error("Failed raising 'finished message processing' event.", exception);
                }
                return;
            }

            try
            {
                OnTransportMessageReceived(message);
            }
            catch (SerializationException serializationException)
            {
                Logger.Error("Failed to deserialize message with ID: " + message.Id, serializationException);

                message.RevertToOriginalBodyIfNeeded();

                FailureManager.SerializationFailedForMessage(message, serializationException);
            }
            catch (Exception)
            {
                //but need to abort takes precedence - failures aren't counted here,
                //so messages aren't moved to the error queue.
                if (!needToAbort)
                {
                    throw;
                }
            }
            finally
            {
                try
                {
                    OnFinishedMessageProcessing(message);
                }
                catch (Exception exception)
                {
                    Logger.Error("Failed raising 'finished message processing' event.", exception);
                    //but need to abort takes precedence - failures aren't counted here,
                    //so messages aren't moved to the error queue.
                    if (!needToAbort)
                    {
                        throw;
                    }
                }
            }
        }