Skip to content

Instantly share code, notes, and snippets.

@frankhale
Last active March 16, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankhale/4ea7a98af9451a71943ecd77efc66d55 to your computer and use it in GitHub Desktop.
Save frankhale/4ea7a98af9451a71943ecd77efc66d55 to your computer and use it in GitHub Desktop.
MassTransit ASPNET Core Azure ServiceBus config fail
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
var queueTopic = "topic name here";
var sendQueueConnectionString = "Send EndPoint Connection String Here";
var receiveQueueConnectionString = "Receive EndPoint COnnection String Here";
// My intent is to have this ASPNET Core API publish and also be a consumer
var azureServiceBusSend = Bus.Factory.CreateUsingAzureServiceBus(busFactoryConfig =>
{
busFactoryConfig.Message<MyMessage>(configTopology =>
{
configTopology.SetEntityName(queueTopic);
});
busFactoryConfig.Host(sendQueueConnectionString, hostConfig => { });
});
var azureServiceBusReceive = Bus.Factory.CreateUsingAzureServiceBus(busFactoryConfig =>
{
busFactoryConfig.Message<MyMessage>(x => { x.SetEntityName(queueTopic); });
busFactoryConfig.Host(receiveQueueConnectionString, hostConfig => { });
busFactoryConfig.ReceiveEndpoint(queueTopic, config =>
{
config.Consumer<MyMessageConsumer>();
});
});
services.AddMassTransit(config =>
{
config.AddBus(provider => azureServiceBusSend);
});
services.AddSingleton<IPublishEndpoint>(azureServiceBusSend);
services.AddSingleton<ISendEndpointProvider>(azureServiceBusSend);
services.AddSingleton<IBus>(azureServiceBusSend);
}
@phatboyg
Copy link

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();

    var queueTopic = "topic name here"; 
    var connectionString = "Connection String Here";
 
    services.AddMassTransit(x =>
    {
        x.AddConsumer<MyMessageConsumer>();

        x.AddBus(context =>Bus.Factory.CreateUsingAzureServiceBus(cfg =>
        {
            cfg.Message<MyMessage>(x => { x.SetEntityName(queueTopic); });
            cfg.Host(connectionString, hostConfig => { });
            cfg.ReceiveEndpoint(queueTopic, e =>
            {
                e.ConfigureConsumer<MyMessageConsumer>(context);
            });
        });
    });
}

@frankhale
Copy link
Author

frankhale commented May 27, 2020

Thank you. I tried this but am getting:

InvalidOperationException: Entity cannot have auto-forwarding policy to itself

@garyman99
Copy link

I'm running in to this error as well. Do I need to be using a premium instance of ASB?

@phatboyg
Copy link

phatboyg commented Mar 15, 2021

No, you just need to make sure you don't have a receive endpoint with the same name as the topic. Pretty common mistake. Specifying custom entity names is the most common path to these type of errors.

@frankhale
Copy link
Author

No, you just need to make sure you don't have a receive endpoint with the same name as the topic.

This was my mistake ^

@garyman99
Copy link

Thanks, guys. This was my problem. It's starting to come together, now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment