【问题标题】:Windows Service Bus - Multiple ReceiversWindows 服务总线 - 多个接收器
【发布时间】:2013-03-06 17:24:15
【问题描述】:

我正在使用安装在本地计算机上的 Windows 服务总线(不是 Azure)。我按照这里的例子,但换成了我的本地实例:http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/

我现在设置了两个控制台应用程序,一个是接收器,另一个是发送器。接收者只是监听新消息并执行输出的console.writeline:

// Continuously process messages sent to the "TestQueue" 
            while (true)
            {
                BrokeredMessage message = Client.Receive();

                if (message != null)
                {
                    try
                    {
                        Console.WriteLine("Body: " + message.GetBody<string>());
                        Console.WriteLine("MessageID: " + message.MessageId);
                        Console.WriteLine("Test Property: " +
                           message.Properties["TestProperty"]);
                        Console.WriteLine("----------------------");

                        // Remove message from queue
                        message.Complete();
                    }
                    catch (Exception)
                    {
                        // Indicate a problem, unlock message in queue
                        message.Abandon();
                    }
                }
            } 

接下来我有我的发件人:

 while (true)
            {

                // Create message, passing a string message for the body
                BrokeredMessage message = new BrokeredMessage("Test message " + i);

                // Set some addtional custom app-specific properties
                message.Properties["TestProperty"] = "TestValue";
                message.Properties["Message number"] = i;

                // Send message to the queue
                Client.Send(message);

                i++;

                System.Threading.Thread.Sleep(50);
            }

这实际上一切都很好。我可以启动 1 个接收者,发送者和我可以看到消息。然后我启动第二个接收器,消息自动在两个接收器之间来回传递。

但是,当我启动第三个接收器时,第一个接收器停止接收消息(直到另一个接收器退出)。

有没有办法让所有三个(或“n”个)接收者处理来自队列的消息?我认为队列设置中可能会有一个设置,但我似乎找不到。

【问题讨论】:

    标签: c# service servicebus


    【解决方案1】:

    如果您减少发送者的睡眠,第一个接收者会开始检索消息吗?可能是您的队列被过度读取,以至于第二个和第三个接收器碰巧检索到消息,但第一个接收器由于队列为空而无法检索到消息。

    您的目标是让独立的读者处理队列,还是在进行一对多通信后,每个接收者都有机会处理消息?如果是这样,那么您应该考虑使用Topics and Subscriptions

    【讨论】:

    • 我放慢了读者的速度,他们现在都在收到消息。所以现在我知道这不是设置问题,而是空队列或其他实例从该队列读取的速度太快。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    相关资源
    最近更新 更多