How does Rebus work with Azure Service Bus topics?

白昼怎懂夜的黑 提交于 2020-05-29 05:14:11

问题


I'm new to Rebus and Azure Service Bus and would like to understand how Rebus works with Azure Service Bus topics and queues.

I've managed to successfully get Rebus to work with ASB but am a bit puzzled as to what's going on under the covers.

I have an ASP.NET Core application that configures Rebus as follows:

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"))
);

I also have a console application that subscribes to the messages, configured as follows:

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...");
}

When I look in the Azure Portal, I see a topic created for each of my message subclasses (I have two) and I see a queue created called "subscriber".

From what I can surmise it would seem that I can just configure a service bus in Azure Portal and the Rebus will create topics as needed for each of the message types. Similarly, the subscribing application will create an input queue as needed.

I'd just like to verify that my understanding is correct.

来源:https://stackoverflow.com/questions/49742699/how-does-rebus-work-with-azure-service-bus-topics

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!