Exemplo n.º 1
0
        async Task ProcessMessage(DefaultTransactionContext context, TransportMessage transportMessage)
        {
            try
            {
                context.Items["OwningBus"]        = _owningBus;
                AmbientTransactionContext.Current = context;

                var incomingSteps = _pipeline.ReceivePipeline();
                var stepContext   = new IncomingStepContext(transportMessage, context);
                await _pipelineInvoker.Invoke(stepContext, incomingSteps);

                try
                {
                    await context.Complete();
                }
                catch (Exception exception)
                {
                    _log.Error(exception, "An error occurred when attempting to complete the transaction context");
                }
            }
            catch (ThreadAbortException exception)
            {
                context.Abort();

                _log.Error(exception, $"Worker was killed while handling message {transportMessage.GetMessageLabel()}");
            }
            catch (Exception exception)
            {
                context.Abort();

                _log.Error(exception, $"Unhandled exception while handling message {transportMessage.GetMessageLabel()}");
            }
            finally
            {
                AmbientTransactionContext.Current = null;
            }
        }