Example #1
0
        public void Invoke(MiddlewareContext context, Action next)
        {
            var channelMessage  = context.ChannelMessage;
            var messageTypeName = channelMessage.GetHeader(MessageHeaders.MessageFullname);
            var handlerInfos    = handlerCache.GetHandlerInfo(messageTypeName).ToList();

            if (handlerInfos.Any())
            {
                var messageType = handlerInfos.First().MessageType;
                context.Message = bodySerializer.Deserialize(channelMessage.BodyStream, messageType);
            }
            else
            {
                context.Message = bodySerializer.Deserialize(channelMessage.BodyStream, typeof(object));
            }

            next();
        }
Example #2
0
        public void Invoke(MiddlewareContext context, Action next)
        {
            var channelMessage  = context.ChannelMessage;
            var messageTypeName = channelMessage.GetHeader(MessageHeaders.MessageFullname);
            var handlerInfos    = handlerCache.GetHandlerInfo(messageTypeName);

            foreach (var info in handlerInfos)
            {
                var handlerType = info.HandlerType;

                log.Verbose($"Invoking handler {handlerType.Name}");

                var result = InvokeHandler(handlerType, context.Message);

                if (!result.Success)
                {
                    throw result.Exception;
                }
            }

            next();
        }
Example #3
0
        public async Task Invoke(MiddlewareContext context, Func <Task> next)
        {
            var basicMessage    = context.BasicMessage;
            var messageTypeName = basicMessage.GetHeader(MessageHeaders.MessageFullname);
            var handlerInfos    = handlerCache.GetHandlerInfo(messageTypeName);

            foreach (var info in handlerInfos)
            {
                var handlerType = info.HandlerType;

                logger.LogDebug($"Invoking handler {handlerType.Name}");

                var result = await InvokeHandler(handlerType, context.Message);

                if (!result.Success)
                {
                    throw result.Exception;
                }
            }

            await next();
        }