Search code examples
azureservicebusmasstransitazure-servicebus-queues

MassTransit command consumer creates a topic. Is this correct?


I'm new to Azure Service Bus and MassTransit and I'm experimenting with sending a simple command to a queue and then having a consumer consume that command. I can successfully get the message sent, and then consumed by my consumer, however I've noticed that a corresponding topic also gets created. My somewhat naive understanding of this is that a topic would only need to be used for event publishing and subscriptions.

This is what sets up my IBus instance, where IMessageBus encapsulates the MassTransit.IBus instance

public static IMessageBus CreateBusAndRegisterQueueConsumer<T>(string servicePath, string queueName, IComponentContext autoFacContext)
            where T : class
        {
            return new MessageBus
            {
                Instance = Bus.Factory.CreateUsingAzureServiceBus(
                    sbc =>
                    {
                        var host = ConfigureServiceBus(servicePath, sbc);
                        sbc.ReceiveEndpoint(host, queueName, ec =>
                        {
                            ec.Consumer<CommandConsumer<T>>(autoFacContext);
                        });
                    })
            };
        }

Is the behaviour that I'm observing correct, in that sending commands will always under the hood create topics, or have I set up my service bus incorrectly? And if it does need to create a topic, is this due to the way MassTransit works, or is this some underlying requirement of Azure Service Bus?

This is what I see in service bus explorer after sending a command


Solution

  • If you don't want the receive endpoint to create/subscribe to topics, you can specify:

    e.SubscribeMessageTopics = false;
    

    By default, all message types are configured on the broker to support publishing. Setting this to false will disable the configuration.