同一消息的多个订阅者重新连接Azure服务总线

问题描述 投票:1回答:1

我有两个完全相同的消费者

消费者1

using (var adapter = new BuiltinHandlerActivator())
        {
            adapter.Handle<string>(async (bus, message) =>
            {
                Console.WriteLine("Got message > " + message);

                await bus.Reply("Received in consumer 1");
            });

            Configure.With(adapter)
                .Transport(t => t.UseAzureServiceBus(connectionString, "server"))
                .Start();

            adapter.Bus.Subscribe<string>().Wait();

            Console.WriteLine("Press ENTER to quit");
            Console.ReadLine();
        }

消费者2

using (var adapter = new BuiltinHandlerActivator())
        {
            adapter.Handle<string>(async (bus, message) =>
            {
                Console.WriteLine("Got message > " + message);

                await bus.Reply("Received in Consumer 2");
            });

            Configure.With(adapter)
                .Transport(t => t.UseAzureServiceBus(connectionString, "server"))
                .Start();

            adapter.Bus.Subscribe<string>().Wait();

            Console.WriteLine("Press ENTER to quit");
            Console.ReadLine();
        }

制作人

using (var adapter = new BuiltinHandlerActivator())
        {
            adapter.Handle<string>(async message =>
            {
                Console.WriteLine("Returned > " + message);
            });

            var bus = Configure
                .With(adapter)
                .Transport(t => t.UseAzureServiceBus(connectionString, "client"))
                .Routing(r => r.TypeBased().Map<string>("server"))
                .Start();

            Console.WriteLine("Press Q to quit or any other key to produce a job");
            while (true)
            {
                Console.Write("Write something > ");
                var text = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(text)) break;

                bus.Publish(text).Wait();
            }
        }

我期望的是,每当我从生产者发送消息时,我的两个消费者都将显示该消息。现在,仅在其中之一中执行此操作。当我关闭该邮件并发送另一封邮件时,剩下的一封邮件会收到。

azure service subscription rebus bus
1个回答
1
投票
[基本上,您只需要给使用者一个不同的名字。 Rebus为每个生产者创建一个主题(基于程序集,名称空间,类型),并在这些主题中为每个消费者创建订阅。如果两个使用者使用相同的名称,他们将争夺消息。

.Transport(t => t.UseAzureServiceBus(connectionString, "consumer1")) .Transport(t => t.UseAzureServiceBus(connectionString, "consumer2"))

完整示例:https://github.com/rebus-org/RebusSamples/tree/master/PubSubNative

一些其他有用的链接:

© www.soinside.com 2019 - 2024. All rights reserved.