DotNetWorkQueue.Queue.MessageExceptionHandler.Handle C# (CSharp) Method

Handle() public method

Handles the specified message.
An error has occurred in the error handling code An unhanded exception has occurred while processing a message
public Handle ( IReceivedMessageInternal message, IMessageContext context, Exception exception ) : void
message IReceivedMessageInternal The message.
context IMessageContext The context.
exception System.Exception The exception.
return void
        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.MesssageId);
                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.MesssageId, message.CorrelationId);
        }
    }

Usage Example

        /// <summary>
        /// Handles processing the specified message with the context
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="transportMessage">The transport message.</param>
        /// <returns></returns>
        public async Task HandleAsync(IMessageContext context, IReceivedMessageInternal transportMessage)
        {
            using (var heartBeat = _heartBeatWorkerFactory.Create(context))
            {
                try
                {
                    await _methodToRun.HandleAsync(transportMessage, context.WorkerNotification).ConfigureAwait(false);

                    _commitMessage.Commit(context);
                }
                // ReSharper disable once UncatchableException
                catch (ThreadAbortException)
                {
                    heartBeat.Stop();
                    throw;
                }
                catch (OperationCanceledException)
                {
                    heartBeat.Stop();
                    throw;
                }
                catch (Exception exception)
                {
                    heartBeat.Stop();
                    _messageExceptionHandler.Handle(transportMessage, context, exception.InnerException ?? exception);
                }
            }
        }
All Usage Examples Of DotNetWorkQueue.Queue.MessageExceptionHandler::Handle
MessageExceptionHandler