我有两个完全相同的消费者
消费者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();
}
}
我期望的是,每当我从生产者发送消息时,我的两个消费者都将显示该消息。现在,仅在其中之一中执行此操作。当我关闭该邮件并发送另一封邮件时,剩下的一封邮件会收到。
.Transport(t => t.UseAzureServiceBus(connectionString, "consumer1"))
.Transport(t => t.UseAzureServiceBus(connectionString, "consumer2"))
完整示例:https://github.com/rebus-org/RebusSamples/tree/master/PubSubNative一些其他有用的链接: