© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
37 replies
M B V R K

✅ Failed to bind to address http://127.0.0.1:5196: address already in use

Hi firends,
I'm working on a project using Microservices, I use
RabbitMQ
RabbitMQ
as the message broker, and the
MassTransit
MassTransit
as the abstraction layer over the
RabbitMQ
RabbitMQ
.
I have a service called AuthService which uses the
RabbitMQ
RabbitMQ
, another service called
ExpenseService.API
ExpenseService.API
also uses the same
RabbitMQ
RabbitMQ


in
appsettings.json
appsettings.json
of both services/projects have the same follwing
RabbitMQ
RabbitMQ
options
"RabbitMQ": {
    "Settings": {
      "HostName": "rabbitmq://localhost",
      "UserName": "guest",
      "Password": "guest"
    },

    "Endpoints": {
      "AuthService": {
        "UserCreatedEventQueue": "AuthService-UserCreatedEventQueue"
      }
    }
  }
"RabbitMQ": {
    "Settings": {
      "HostName": "rabbitmq://localhost",
      "UserName": "guest",
      "Password": "guest"
    },

    "Endpoints": {
      "AuthService": {
        "UserCreatedEventQueue": "AuthService-UserCreatedEventQueue"
      }
    }
  }


in the
program.cs
program.cs
of
ExpenseService.API
ExpenseService.API
I have this part which configure the project to be a consumer/subscriber :
var authServiceRabbitMqEndPointsOptions = builder.Configuration.GetSection("RabbitMQ:EndPoints:AuthService").Get<AuthServiceRabbitMqEndpointsOptions>();
var authServiceRabbitMqEndPoints = authServiceRabbitMqEndPointsOptions;


builder.Services.AddMassTransit( busConfigurator => 
{
    busConfigurator.UsingRabbitMq((context, cfg) => 
    {
        cfg.ReceiveEndpoint(authServiceRabbitMqEndPoints.UserCreatedEventQueue, ep => ep.Consumer<UserCreatedMessageConsumer>());
    });
});
var authServiceRabbitMqEndPointsOptions = builder.Configuration.GetSection("RabbitMQ:EndPoints:AuthService").Get<AuthServiceRabbitMqEndpointsOptions>();
var authServiceRabbitMqEndPoints = authServiceRabbitMqEndPointsOptions;


builder.Services.AddMassTransit( busConfigurator => 
{
    busConfigurator.UsingRabbitMq((context, cfg) => 
    {
        cfg.ReceiveEndpoint(authServiceRabbitMqEndPoints.UserCreatedEventQueue, ep => ep.Consumer<UserCreatedMessageConsumer>());
    });
});


When I start
AuthService
AuthService
then
ExpenseService
ExpenseService
I get this exception :

Exception has occurred: CLR/System.IO.IOException
An unhandled exception of type 'System.IO.IOException' occurred in System.Private.CoreLib.dll: 'Failed to bind to address http://127.0.0.1:5196: address already in use.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.Net.Sockets.SocketException : Only one usage of each socket address (protocol/network address/port) is normally permitted.

Please I hope someone to provide a help here and massive thanks in advance
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Address already in use after a kill process
C#CC# / help
4y ago
❔ Avoiding "MySql connection is already in use"
C#CC# / help
3y ago
gRPC with HTTP/2.0
C#CC# / help
2y ago
❔ Unable to bind to list in picker, MAUI
C#CC# / help
3y ago