Rebus 如何与 Azure 服务总线主题配合使用?

2024-04-04

我是 Rebus 和 Azure 服务总线的新手,想了解 Rebus 如何与 Azure 服务总线主题和队列配合使用。

我已经成功地让 Rebus 与 ASB 合作,但对幕后发生的事情有点困惑。

我有一个 ASP.NET Core 应用程序,它配置 Rebus 如下:

services.AddRebus(configure => configure
    .Logging(l => l.Serilog())
    .Transport(t =>
        {
            switch (messagingConfig)
            {
                case MessagingConfig.RabbitMq:
                    t.UseRabbitMqAsOneWayClient(messagingConnectionString);
                    break;
                case MessagingConfig.AzureServiceBus:
                    t.UseAzureServiceBusAsOneWayClient(messagingConnectionString);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        })
    .Routing(r => r.TypeBased().Map<BaseMessage>("publisher"))
);

我还有一个订阅消息的控制台应用程序,配置如下:

using (var activator = new BuiltinHandlerActivator())
{
    activator.Register(() => new Handler());

    Configure.With(activator)
        .Logging(l => l.ColoredConsole(minLevel: LogLevel.Warn))
        .Transport(t =>
        {
            switch (BusConfig)
            {
                case MessagingConfig.RabbitMq:
                    t.UseRabbitMq(RabbitMqConnectionString, "consumer");
                    break;
                case MessagingConfig.AzureServiceBus:
                    t.UseAzureServiceBus(AzureServiceBusConnectionString, "subscriber");
                    break;
            }
        })
        .Start();

    Console.WriteLine($"Listening for messages on {BusConfig}...");
    Console.WriteLine("Press ENTER to quit");

    activator.Bus.Subscribe<AdditionalSessionRequestMessage>().Wait();
    activator.Bus.Subscribe<AcceptInvoiceMessage>().Wait();

    Console.ReadLine();

    Console.WriteLine("Quitting...");
}

当我查看 Azure 门户时,我看到为每个消息子类(我有两个)创建了一个主题,并且看到创建了一个名为“订阅者”的队列。

据我推测,我似乎只需在 Azure 门户中配置服务总线,Rebus 将根据需要为每种消息类型创建主题。类似地,订阅应用程序将根据需要创建输入队列。

我只是想验证一下我的理解是否正确。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rebus 如何与 Azure 服务总线主题配合使用? 的相关文章

随机推荐