简体   繁体   English

仅在完成Handle方法的执行之后,NServiceBus中单个请求的多个响应才到达目标

[英]Multiple responses for a single request in NServiceBus reaches the destination only after the completing the execution of Handle method

To increase the responsiveness of the application the Message handler is responding with multiple responses. 为了提高应用程序的响应能力,消息处理程序使用多个响应进行响应。 But its observed that the messages are delivered to the destination only after the message handling is fully completed even though the transaction is disabled as follows var busConfiguration = new BusConfiguration(); 但是它观察到,即使事务被禁用,消息也仅在消息处理完全完成后才传递到目标。var busConfiguration = new BusConfiguration(); busConfiguration.Transactions().Disable(); 。busConfiguration.Transactions()禁用();

we have the code as follows: using MyMessages; 我们的代码如下:使用MyMessages; using NServiceBus; 使用NServiceBus; using System; 使用系统;

    public class RequestDataMessageHandler : IHandleMessages<RequestDataMessage>
    {
        public IBus Bus { get; set; }

        public void Handle(RequestDataMessage message)
        {

            Console.WriteLine("Received request {0}.", message.DataId);
            Console.WriteLine("String received: {0}.", message.String);

            var response1 = new DataResponseMessage
            {
                DataId = message.DataId,
                String = "InProgress"
            };

            Bus.Reply(response1);


            try
            {
                TimeConsumingActivity();
                var response = new DataResponseMessage
                {
                    DataId = message.DataId,
                    String = message.String
                };

                Bus.Reply(response);
            }
            catch
            {
                var response2 = new DataResponseMessage
                {
                    DataId = message.DataId,
                    String = "Error in the process"            
                };
                Bus.Reply(response2);
            }
        }
    }

but its observer that response1 and response reaches destination only after TimeConsumingActivity is done (This is not the problem of the order) 但其观察者认为response1和response仅在TimeConsumingActivity完成后才到达目的地(这不是顺序的问题)

Try: 尝试:

 busConfiguration.Transactions().DoNotWrapHandlersExecutionInATransactionScope();

So, this is to the best of my understanding. 因此,据我所知。 There are several settings relating to transactions in NSB configuration, and I'm not sure I can definitively describe the differences between them. NSB配置中有一些与事务相关的设置,我不确定是否可以确切描述它们之间的区别。

The setting above should should prevent your handlers from being wrapped in a TransactionScope, which (if not disabled) could account for reply message not getting "released" to the bus until the transaction is completed. 上面的设置应该防止您的处理程序被封装在TransactionScope中,如果未禁用,则该事务范围(如果未禁用) 可以解释直到事务完成之前应答消息才不会“释放”到总线上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM