C
C#16mo ago
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 as the message broker, and the MassTransit as the abstraction layer over the RabbitMQ. I have a service called AuthService which uses the RabbitMQ, another service called ExpenseService.API also uses the same RabbitMQ in appsettings.json of both services/projects have the same follwing 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 of 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 then 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
10 Replies
Pobiega
Pobiega16mo ago
You have two or more listeners on the same port. Its as easy as that.
M B V R K
M B V R KOP16mo ago
listeners means apps ?
Pobiega
Pobiega16mo ago
could be. are your microservices using http listeners? in that case, yes check the logs of each service asp.net prints the port its listening on in each service
M B V R K
M B V R KOP16mo ago
Yeah the AuthService is running on http://localhost:5196/ and when I start the ExpenseService I get the exception I mentionned
Pobiega
Pobiega16mo ago
right so they are trying to listen on the same port thats a no-go, so you need to change the launch settings for one of them
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega16mo ago
very cool powershell script, wont help here thou 😄
M B V R K
M B V R KOP16mo ago
hmmm, you mean exactly the port ?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
M B V R K
M B V R KOP16mo ago
@TeBeClone Yeah, very clear, I really appreciate your help and time man
Want results from more Discord servers?
Add your server