예제 #1
0
        public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func <Task> next)
        {
            var messageType = context.LogicalMessage.Instance.GetType();

            var handlers = registry.GetHandlers(messageType);

            foreach (var handler in handlers)
            {
                var messageHandler = new MessageHandler
                {
                    Instance   = handler,
                    Invocation = (handlerInstance, message) => registry.InvokeHandle(handlerInstance, message, bus)
                };

                context.Handler = messageHandler;

                await next()
                .ConfigureAwait(false);

                if (context.HandlerInvocationAbortPending)
                {
                    break;
                }
            }
        }
        public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func<Task> next)
        {
            var messageType = context.LogicalMessage.Instance.GetType();

            var handlers = registry.GetHandlers(messageType);

            foreach (var handler in handlers)
            {
                using (context.CreateSnapshot())
                {
                    var messageHandler = new MessageHandler
                    {
                        Instance = handler,
                        Invocation = (handlerInstance, message) => registry.InvokeHandle(handlerInstance, message, bus)
                    };

                    context.Handler = messageHandler;

                    await next()
                        .ConfigureAwait(false);

                    if (context.HandlerInvocationAbortPending)
                    {
                        break;
                    }
                }
            }
        }
예제 #3
0
        public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func<Task> next)
        {
            var messageHandler = context.Handler;

            await messageHandler.Invocation(messageHandler.Instance, context.LogicalMessage.Instance)
                .ConfigureAwait(false);

            await next()
                .ConfigureAwait(false);
        }
예제 #4
0
        public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func <Task> next)
        {
            var messageHandler = context.Handler;

            await messageHandler.Invocation(messageHandler.Instance, context.LogicalMessage.Instance)
            .ConfigureAwait(false);

            await next()
            .ConfigureAwait(false);
        }
예제 #5
0
        Task InvokeLogical(IncomingLogicalContext context, IBusForHandler bus, int currentIndex = 0)
        {
            if (currentIndex == registeredLogicalPipeline.Count)
            {
                return Task.CompletedTask;
            }

            IIncomingLogicalStep step = registeredLogicalPipeline[currentIndex];

            return step.Invoke(context, bus, () => InvokeLogical(context, bus, currentIndex + 1));
        }
예제 #6
0
        Task InvokeLogical(IncomingLogicalContext context, IBusForHandler bus)
        {
            if (executingLogicalPipeline.Count == 0)
            {
                return(Task.FromResult(0));
            }

            IIncomingLogicalStep step = executingLogicalPipeline.Dequeue();

            return(step.Invoke(context, bus, () => InvokeLogical(context, bus)));
        }
예제 #7
0
        Task InvokeLogical(IncomingLogicalContext context, IBusForHandler bus, int currentIndex = 0)
        {
            if (currentIndex == registeredLogicalPipeline.Count)
            {
                return(Task.CompletedTask);
            }

            IIncomingLogicalStep step = registeredLogicalPipeline[currentIndex];

            return(step.Invoke(context, bus, () => InvokeLogical(context, bus, currentIndex + 1)));
        }
예제 #8
0
 private static async Task InvokeWithDelay(IncomingLogicalContext context, Func <Task> next, int delay)
 {
     try
     {
         await next().ConfigureAwait(false);
     }
     catch (Exception)
     {
         delay += 100;
         await Task.Delay(delay);
         await InvokeWithDelay(context, next, delay);
     }
 }
 private static async Task InvokeWithDelay(IncomingLogicalContext context, Func<Task> next, int delay)
 {
     try
     {
         await next().ConfigureAwait(false);
     }
     catch (Exception)
     {
         delay += 100;
         await Task.Delay(delay);
         await InvokeWithDelay(context, next, delay);
     }
 }
예제 #10
0
        public async Task Invoke(IBusForHandler bus, TransportMessage message, EndpointConfiguration.ReadOnly configuration)
        {
            var transportContext = new IncomingTransportContext(message, configuration);
            await InvokeTransport(transportContext, bus)
                .ConfigureAwait(false);

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

            var logicalContext = new IncomingLogicalContext(logicalMessage, message, configuration);
            currentContext = logicalContext;
            await InvokeLogical(logicalContext, bus)
                .ConfigureAwait(false);
        }
예제 #11
0
        public async Task Invoke(IBusForHandler bus, TransportMessage message, EndpointConfiguration.ReadOnly configuration)
        {
            var transportContext = new IncomingTransportContext(message, configuration);

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

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

            var logicalContext = new IncomingLogicalContext(logicalMessage, message, configuration);

            currentContext = logicalContext;
            await InvokeLogical(logicalContext, bus)
            .ConfigureAwait(false);
        }
예제 #12
0
        public async Task Invoke(IBusForHandler bus, TransportMessage message, EndpointConfiguration.ReadOnly configuration)
        {
            executingTransportPipeline = new Queue <IIncomingTransportStep>(registeredTransportPipeline);
            var transportContext = new IncomingTransportContext(message, configuration);

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

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

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

            logicalContext.SetChain(this);
            currentContext = logicalContext;
            await InvokeLogical(logicalContext, bus)
            .ConfigureAwait(false);
        }
        public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func<Task> next)
        {
            try
            {
                await next()
                    .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                var message = context.TransportMessage;
                if (IsRetryCountReached(context))
                {
                    message.SetFailureHeaders(exception, "Max number of retries has been reached!");

                    // C# 6 can do this!
                    await deadLetter.DeadLetterAsync(message).ConfigureAwait(false);
                }
                else
                {
                    message.DeliveryCount++;
                    throw;
                }
            }
        }
        public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func <Task> next)
        {
            try
            {
                await next()
                .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                var message = context.TransportMessage;
                if (IsRetryCountReached(context))
                {
                    message.SetFailureHeaders(exception, "Max number of retries has been reached!");

                    // C# 6 can do this!
                    await deadLetter.DeadLetterAsync(message).ConfigureAwait(false);
                }
                else
                {
                    message.DeliveryCount++;
                    throw;
                }
            }
        }
예제 #15
0
 public Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func<Task> next)
 {
     collector.Add(context.LogicalMessage);
     return next();
 }
예제 #16
0
        Task InvokeLogical(IncomingLogicalContext context, IBusForHandler bus)
        {
            if (executingLogicalPipeline.Count == 0)
            {
                return Task.FromResult(0);
            }

            IIncomingLogicalStep step = executingLogicalPipeline.Dequeue();

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

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

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

                return step.Invoke(context, bus, next);
            }
예제 #19
0
 public Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func<Task> next)
 {
     var delay = 100;
     return InvokeWithDelay(context, next, delay);
 }
예제 #20
0
        public Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func <Task> next)
        {
            var delay = 100;

            return(InvokeWithDelay(context, next, delay));
        }
        static bool IsRetryCountReached(IncomingLogicalContext context)
        {
            const int HardcodedMaxRetryOfServiceBusLibrary = 10;

            return(context.TransportMessage.DeliveryCount > HardcodedMaxRetryOfServiceBusLibrary - 1);
        }
 static bool IsRetryCountReached(IncomingLogicalContext context)
 {
     const int HardcodedMaxRetryOfServiceBusLibrary = 10;
     return context.TransportMessage.DeliveryCount > HardcodedMaxRetryOfServiceBusLibrary - 1;
 }
예제 #23
0
            public Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func <Task> next)
            {
                var step = factory();

                return(step.Invoke(context, bus, next));
            }