コード例 #1
0
        private async Task SendResponse(FlowContext context, object message)
        {
            var reply = context.FlowState == null
                ? GetReply(context.HandlerContext)
                : context.FlowState.Metadata.Reply;

            if (reply == null)
            {
                throw new YieldPointException("No response is required");
            }

            if (message.GetType().FullName != reply.ResponseTypeName)
            {
                throw new YieldPointException($"Flow must end with a response message of type {reply.ResponseTypeName}, {message.GetType().FullName} was returned instead");
            }

            var properties = new MessageProperties
            {
                CorrelationId = reply.CorrelationId
            };

            // TODO disallow if replyto is not specified?
            if (reply.ReplyTo != null)
            {
                await publisher.PublishDirect(message, reply.ReplyTo, properties, reply.Mandatory);
            }
            else
            {
                await publisher.Publish(message, properties, reply.Mandatory);
            }

            await context.Delete();
        }
コード例 #2
0
        private static async Task EndFlow(FlowContext context)
        {
            await context.Delete();

            if (context.FlowState?.Metadata.Reply != null)
            {
                throw new YieldPointException($"Flow must end with a response message of type {context.FlowState.Metadata.Reply.ResponseTypeName}");
            }
        }
コード例 #3
0
        private async Task SendResponse(FlowContext context, object message)
        {
            var reply = context.FlowState == null
                ? GetReply(context.MessageContext)
                : context.FlowState.Metadata.Reply;

            if (reply == null)
            {
                throw new YieldPointException("No response is required");
            }

            if (message.GetType().FullName != reply.ResponseTypeName)
            {
                throw new YieldPointException($"Flow must end with a response message of type {reply.ResponseTypeName}, {message.GetType().FullName} was returned instead");
            }

            var properties = new BasicProperties();

            // Only set the property if it's not null, otherwise a string reference exception can occur:
            // http://rabbitmq.1065348.n5.nabble.com/SocketException-when-invoking-model-BasicPublish-td36330.html
            if (reply.CorrelationId != null)
            {
                properties.CorrelationId = reply.CorrelationId;
            }

            // TODO disallow if replyto is not specified?
            if (reply.ReplyTo != null)
            {
                await publisher.PublishDirect(message, reply.ReplyTo, properties);
            }
            else
            {
                await publisher.Publish(message, properties);
            }

            await context.Delete();
        }