예제 #1
0
        public async Task Invoke(IncomingTransportContext context, IBusForHandler bus, Func <Task> next)
        {
            ExceptionDispatchInfo serializationException = null;

            try
            {
                await next()
                .ConfigureAwait(false);
            }
            catch (SerializationException exception)
            {
                // We can't do async in a catch block, therefore we have to capture the exception!
                serializationException = ExceptionDispatchInfo.Capture(exception);
            }

            if (SerializationExceptionHasBeenCaught(serializationException))
            {
                var message = context.TransportMessage;

// ReSharper disable PossibleNullReferenceException
                message.SetFailureHeaders(serializationException.SourceException, "Messages which can't be deserialized are deadlettered immediately");
// ReSharper restore PossibleNullReferenceException
                await message.DeadLetterAsync()
                .ConfigureAwait(false);

                // Because we instructed the message to deadletter it is safe to rethrow. The broker will not redeliver.
                serializationException.Throw();
            }
        }
        public async Task Invoke(IncomingTransportContext context, IBusForHandler bus, Func<Task> next)
        {
            ExceptionDispatchInfo serializationException = null;
            try
            {
                await next()
                    .ConfigureAwait(false);
            }
            catch (SerializationException exception)
            {
                // We can't do async in a catch block, therefore we have to capture the exception!
                serializationException = ExceptionDispatchInfo.Capture(exception);
            }

            if (SerializationExceptionHasBeenCaught(serializationException))
            {
                var message = context.TransportMessage;

// ReSharper disable PossibleNullReferenceException
                message.SetFailureHeaders(serializationException.SourceException, "Messages which can't be deserialized are deadlettered immediately");
// ReSharper restore PossibleNullReferenceException
                await message.DeadLetterAsync()
                    .ConfigureAwait(false);

                // Because we instructed the message to deadletter it is safe to rethrow. The broker will not redeliver.
                serializationException.Throw();
            }
        }
예제 #3
0
        private Task InvokeTransport(IncomingTransportContext context, IBusForHandler bus)
        {
            if (this.executingTransportPipeline.Count == 0)
            {
                return(Task.FromResult(0));
            }

            IIncomingTransportStep step = this.executingTransportPipeline.Dequeue();

            return(step.Invoke(context, bus, () => this.InvokeTransport(context, bus)));
        }
        public Task Invoke(IncomingTransportContext context, IBusForHandler bus, Func<Task> next)
        {
            var transportMessage = context.TransportMessage;

            try
            {
                context.Set(this.Extract(transportMessage));
            }
            catch (Exception exception)
            {
                throw new SerializationException(string.Format("An error occurred while attempting to extract logical messages from transport message {0}", transportMessage), exception);
            }

            return next();
        }
        public Task Invoke(IncomingTransportContext context, IBusForHandler bus, Func <Task> next)
        {
            var transportMessage = context.TransportMessage;

            try
            {
                context.Set(this.Extract(transportMessage));
            }
            catch (Exception exception)
            {
                throw new SerializationException(string.Format("An error occurred while attempting to extract logical messages from transport message {0}", transportMessage), exception);
            }

            return(next());
        }
예제 #6
0
        public async Task Invoke(IBusForHandler bus, TransportMessage message, EndpointConfiguration.ReadOnly configuration)
        {
            this.executingTransportPipeline = new Queue <IIncomingTransportStep>(this.registeredTransportPipeline);
            var transportContext = new IncomingTransportContext(message, configuration);

            transportContext.SetChain(this);
            await this.InvokeTransport(transportContext, bus)
            .ConfigureAwait(false);

            // We assume that someone in the pipeline made logical message
            var logicalMessage = transportContext.Get <LogicalMessage>();

            this.executingLogicalPipeline = new Queue <IIncomingLogicalStep>(this.registeredLogicalPipeline);
            var logicalContext = new IncomingLogicalContext(logicalMessage, message, configuration);

            logicalContext.SetChain(this);
            this.currentContext = logicalContext;
            await this.InvokeLogical(logicalContext, bus)
            .ConfigureAwait(false);
        }
예제 #7
0
            public Task Invoke(IncomingTransportContext context, IBusForHandler bus, Func <Task> next)
            {
                var step = this.factory();

                return(step.Invoke(context, bus, next));
            }
예제 #8
0
        public async Task Invoke(IBusForHandler bus, TransportMessage message, EndpointConfiguration.ReadOnly configuration)
        {
            this.executingTransportPipeline = new Queue<IIncomingTransportStep>(this.registeredTransportPipeline);
            var transportContext = new IncomingTransportContext(message, configuration);
            transportContext.SetChain(this);
            await this.InvokeTransport(transportContext, bus)
                .ConfigureAwait(false);

            // We assume that someone in the pipeline made logical message
            var logicalMessage = transportContext.Get<LogicalMessage>();

            this.executingLogicalPipeline = new Queue<IIncomingLogicalStep>(this.registeredLogicalPipeline);
            var logicalContext = new IncomingLogicalContext(logicalMessage, message, configuration);
            logicalContext.SetChain(this);
            this.currentContext = logicalContext;
            await this.InvokeLogical(logicalContext, bus)
                .ConfigureAwait(false);
        }
예제 #9
0
            public Task Invoke(IncomingTransportContext context, IBusForHandler bus, Func<Task> next)
            {
                var step = this.factory();

                return step.Invoke(context, bus, next);
            }
예제 #10
0
        private Task InvokeTransport(IncomingTransportContext context, IBusForHandler bus)
        {
            if (this.executingTransportPipeline.Count == 0)
            {
                return Task.FromResult(0);
            }

            IIncomingTransportStep step = this.executingTransportPipeline.Dequeue();

            return step.Invoke(context, bus, () => this.InvokeTransport(context, bus));
        }