/// <inheritdoc />
        public ReceiveMessagesErrorResult MessageFailedProcessing(IReceivedMessageInternal message, IMessageContext context, Exception exception)
        {
            var spanContext = message.Extract(_tracer, _headers);

            if (spanContext != null)
            {
                using (IScope scope = _tracer.BuildSpan("Error").AddReference(References.FollowsFrom, spanContext).StartActive(finishSpanOnDispose: true))
                {
                    scope.Span.Log(exception.ToString());
                    Tags.Error.Set(scope.Span, true);
                    var result = _handler.MessageFailedProcessing(message, context, exception);
                    scope.Span.SetTag("WillRetry", result == ReceiveMessagesErrorResult.Retry);
                    return(result);
                }
            }
            else
            {
                using (IScope scope = _tracer.BuildSpan("Error").StartActive(finishSpanOnDispose: true))
                {
                    scope.Span.AddMessageIdTag(message);
                    scope.Span.Log(exception.ToString());
                    Tags.Error.Set(scope.Span, true);
                    var result = _handler.MessageFailedProcessing(message, context, exception);
                    scope.Span.SetTag("WillRetry", result == ReceiveMessagesErrorResult.Retry);
                    return(result);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="context">The context.</param>
        /// <param name="exception">The exception.</param>
        /// <exception cref="DotNetWorkQueueException">An error has occurred in the error handling code</exception>
        /// <exception cref="MessageException">An unhanded exception has occurred while processing a message</exception>
        public void Handle(IReceivedMessageInternal message, IMessageContext context, Exception exception)
        {
            ReceiveMessagesErrorResult result;

            try
            {
                result = _transportErrorHandler.MessageFailedProcessing(message, context,
                                                                        exception);
            }
            catch (Exception errorHandlingError)
            {
                _log.ErrorException(
                    "An error has occurred while trying to move message {0} to the error queue", exception,
                    message.MessageId);
                throw new DotNetWorkQueueException("An error has occurred in the error handling code",
                                                   errorHandlingError);
            }

            switch (result)
            {
            case ReceiveMessagesErrorResult.Retry:
            case ReceiveMessagesErrorResult.NotSpecified:
            case ReceiveMessagesErrorResult.NoActionPossible:
                throw new MessageException("An unhanded exception has occurred while processing a message",
                                           exception, message.MessageId, message.CorrelationId);

            case ReceiveMessagesErrorResult.Error:     //don't throw exception, as the message has been moved
                break;
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public ReceiveMessagesErrorResult MessageFailedProcessing(IReceivedMessageInternal message, IMessageContext context, Exception exception)
        {
            var activityContext = message.Extract(_tracer, _headers);

            using (var scope = _tracer.StartActivity("Error", ActivityKind.Internal, parentContext: activityContext))
            {
                scope?.AddMessageIdTag(message);
                scope?.RecordException(exception);
                scope?.SetStatus(Status.Error);;
                var result = _handler.MessageFailedProcessing(message, context, exception);
                scope?.SetTag("WillRetry", result == ReceiveMessagesErrorResult.Retry);
                return(result);
            }
        }
        /// <summary>
        /// Invoked when a message has failed to process.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="context">The context.</param>
        /// <param name="exception">The exception.</param>
        /// <returns>
        /// Result of error processing
        /// </returns>
        public ReceiveMessagesErrorResult MessageFailedProcessing(IReceivedMessageInternal message, IMessageContext context,
                                                                  Exception exception)
        {
            var result = _handler.MessageFailedProcessing(message, context, exception);

            switch (result)
            {
            case ReceiveMessagesErrorResult.Error:
                _meterError.Mark();
                break;

            case ReceiveMessagesErrorResult.Retry:
                _meterRetry.Mark();
                break;
            }
            return(result);
        }
 /// <summary>
 /// Handles the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="context">The context.</param>
 /// <param name="exception">The exception.</param>
 /// <exception cref="DotNetWorkQueueException">An error has occurred in the error handling code</exception>
 /// <exception cref="MessageException">An unhanded exception has occurred while processing a message</exception>
 public void Handle(IReceivedMessageInternal message, IMessageContext context, Exception exception)
 {
     try
     {
         _transportErrorHandler.MessageFailedProcessing(message, context,
                                                        exception);
     }
     catch (Exception errorHandlingError)
     {
         _log.ErrorException(
             "An error has occurred while trying to move message {0} to the error queue", exception,
             message.MessageId);
         throw new DotNetWorkQueueException("An error has occurred in the error handling code",
                                            errorHandlingError);
     }
     throw new MessageException("An unhanded exception has occurred while processing a message",
                                exception, message.MessageId, message.CorrelationId);
 }