Exemplo n.º 1
0
        public async Task Cleanup(IControllerMessageContext context, ConsumeResult consumeResult, Func <Task> next)
        {
            await next();

            if (!context.Get(ContextItems.FlowContext, out FlowContext flowContext))
            {
                return;
            }

            if (flowContext.ContinuationMetadata.MethodName != MethodSerializer.Serialize(context.Binding.Method))
            {
                // Do not call when the controller method was filtered, if the same message has two methods
                return;
            }

            if (flowContext.FlowStateLock != null)
            {
                if (!flowContext.IsStoredOrDeleted())
                {
                    // The exception strategy can set the consume result to Success. Instead, check if the yield point
                    // was handled. The flow provider ensures we only end up here in case of an exception.
                    await flowContext.FlowStateLock.DeleteFlowState();
                }

                flowContext.FlowStateLock.Dispose();
            }
        }
Exemplo n.º 2
0
        private static ResponseHandlerInfo GetResponseHandlerInfo(IConfig config, object request, Delegate responseHandler)
        {
            var binding = config.GetBinding(responseHandler);

            if (binding == null)
            {
                throw new ArgumentException("responseHandler must be a registered message handler", nameof(responseHandler));
            }

            var requestAttribute = request.GetType().GetCustomAttribute <RequestAttribute>();

            if (requestAttribute?.Response != null && requestAttribute.Response != binding.MessageClass)
            {
                throw new ArgumentException($"responseHandler must accept message of type {binding.MessageClass}", nameof(responseHandler));
            }

            var continuationAttribute = binding.Method.GetCustomAttribute <ContinuationAttribute>();

            if (continuationAttribute == null)
            {
                throw new ArgumentException("responseHandler must be marked with the Continuation attribute", nameof(responseHandler));
            }

            if (binding.QueueName == null)
            {
                throw new ArgumentException("responseHandler must bind to a valid queue", nameof(responseHandler));
            }

            return(new ResponseHandlerInfo
            {
                MethodName = MethodSerializer.Serialize(responseHandler.Method),
                ReplyToQueue = binding.QueueName
            });
        }
Exemplo n.º 3
0
        public async Task Filter(IControllerMessageContext context, Func <Task> next)
        {
            var flowContext = await EnrichWithFlowContext(context);

            if (flowContext?.ContinuationMetadata == null)
            {
                return;
            }

            if (flowContext.ContinuationMetadata.MethodName != MethodSerializer.Serialize(context.Binding.Method))
            {
                return;
            }

            await next();
        }
        public async Task Handle(IMessageContext context, Func <Task> next)
        {
            var flowContext = await GetFlowContext(context);

            if (flowContext?.ContinuationMetadata == null)
            {
                return;
            }

            if (flowContext.ContinuationMetadata.MethodName != MethodSerializer.Serialize(context.Binding.Method))
            {
                return;
            }

            await next();
        }
Exemplo n.º 5
0
        private static ResponseHandlerInfo GetResponseHandlerInfo(ITapetiConfig config, object request, Delegate responseHandler)
        {
            var requestAttribute = request.GetType().GetCustomAttribute <RequestAttribute>();

            if (requestAttribute?.Response == null)
            {
                throw new ArgumentException($"Request message {request.GetType().Name} must be marked with the Request attribute and a valid Response type", nameof(request));
            }

            var binding = config.Bindings.ForMethod(responseHandler);

            if (binding == null)
            {
                throw new ArgumentException("responseHandler must be a registered message handler", nameof(responseHandler));
            }

            if (!binding.Accept(requestAttribute.Response))
            {
                throw new ArgumentException($"responseHandler must accept message of type {requestAttribute.Response}", nameof(responseHandler));
            }

            var continuationAttribute = binding.Method.GetCustomAttribute <ContinuationAttribute>();

            if (continuationAttribute == null)
            {
                throw new ArgumentException("responseHandler must be marked with the Continuation attribute", nameof(responseHandler));
            }

            if (binding.QueueName == null)
            {
                throw new ArgumentException("responseHandler is not yet subscribed to a queue, TapetiConnection.Subscribe must be called before starting a flow", nameof(responseHandler));
            }

            return(new ResponseHandlerInfo
            {
                MethodName = MethodSerializer.Serialize(responseHandler.Method),
                ReplyToQueue = binding.QueueName,
                IsDurableQueue = binding.QueueType == QueueType.Durable
            });
        }