C
C#11mo ago
M B V R K

✅ MassTransit with RabbitMQ Exception

Hi friends, I'm working on a project using Microservices, in this project I have ExpenseService ( which divided to 4 projects Domain, Infraastructure, Application and API ), and AuthService. AuthService is used for authentication and user management, the ExpenseService needs to store some info about a User in its own database, so for this when a user is created in AuthService the AuthService publish a UserCreatedMessage/Event to RabbitMQ using MassTransit, the ExpenseService is a subscriber in the Queue if that message. The issue : When I start the both services everything going fine but when I create a user using the AuthService API the User is created and stored in the AuthService database, after that a UserCreatedMessage/Event should be published, but instead I get an Exception in the API that said :
The entity name must not be null or empty
and in VS Code debugging console I get this exception
Exception thrown: 'MassTransit.RabbitMqAddressException' in MassTransit.RabbitMqTransport.dll Exception thrown: 'MassTransit.RabbitMqAddressException' in System.Private.CoreLib.dll
This means that the message is not published because of an issue in MassTransit Configs I did.
7 Replies
M B V R K
M B V R K11mo ago
AuthService program.cs:
builder.Services.ConfigureRabbitMQ(builder.Configuration);

var rabbitMqOptions = builder.Configuration.GetSection("RabbitMQ:Settings").Get<RabbitMqOptions>();

builder.Services.AddMassTransit(busConfigurator =>
{
busConfigurator.UsingRabbitMq((context, cfg) =>
{
cfg.Host($"{rabbitMqOptions.HostName}:{rabbitMqOptions.Port}", h =>
{
h.Username(rabbitMqOptions.UserName);
h.Password(rabbitMqOptions.Password);
});
});
});
builder.Services.ConfigureRabbitMQ(builder.Configuration);

var rabbitMqOptions = builder.Configuration.GetSection("RabbitMQ:Settings").Get<RabbitMqOptions>();

builder.Services.AddMassTransit(busConfigurator =>
{
busConfigurator.UsingRabbitMq((context, cfg) =>
{
cfg.Host($"{rabbitMqOptions.HostName}:{rabbitMqOptions.Port}", h =>
{
h.Username(rabbitMqOptions.UserName);
h.Password(rabbitMqOptions.Password);
});
});
});
ExoenseService program.cs:
var rabbitMqOptions = builder.Configuration.GetSection("RabbitMQ:Settings").Get<RabbitMqOptions>();
var authServiceRabbitMqEndPointsOptions = builder.Configuration.GetSection("RabbitMQ:EndPoints:AuthService").Get<AuthServiceRabbitMqEndpointsOptions>();
var authServiceRabbitMqEndPoints = authServiceRabbitMqEndPointsOptions;

builder.Services.AddMassTransit(busConfigurator =>
{
busConfigurator.UsingRabbitMq((context, cfg) =>
{
cfg.Host($"{rabbitMqOptions.HostName}:{rabbitMqOptions.Port}", h =>
{
h.Username(rabbitMqOptions.UserName);
h.Password(rabbitMqOptions.Password);
});

cfg.ReceiveEndpoint(authServiceRabbitMqEndPoints.UserCreatedEventQueue, ep => ep.Consumer<UserCreatedMessageConsumer>());
});
});
var rabbitMqOptions = builder.Configuration.GetSection("RabbitMQ:Settings").Get<RabbitMqOptions>();
var authServiceRabbitMqEndPointsOptions = builder.Configuration.GetSection("RabbitMQ:EndPoints:AuthService").Get<AuthServiceRabbitMqEndpointsOptions>();
var authServiceRabbitMqEndPoints = authServiceRabbitMqEndPointsOptions;

builder.Services.AddMassTransit(busConfigurator =>
{
busConfigurator.UsingRabbitMq((context, cfg) =>
{
cfg.Host($"{rabbitMqOptions.HostName}:{rabbitMqOptions.Port}", h =>
{
h.Username(rabbitMqOptions.UserName);
h.Password(rabbitMqOptions.Password);
});

cfg.ReceiveEndpoint(authServiceRabbitMqEndPoints.UserCreatedEventQueue, ep => ep.Consumer<UserCreatedMessageConsumer>());
});
});
Please I hope someone to provide a help <3
M B V R K
M B V R K11mo ago
M B V R K
M B V R K11mo ago
cap5lut
cap5lut11mo ago
it only seems like a configuration issue on ur services side if the host and/or port are wrong my first step would be to use some rabbitmq health check tool to see if rabbitmq is actually set up correctly. since 15672 seems to be an http port it might also be that rabbitmq is only listening on a specific domain, and refuses on different hosts (HTTP Host header basically) scratch the last part, that cant be it, because ur client isnt even able to send headers yet basically this should give some hints whats going wrong: https://www.rabbitmq.com/troubleshooting-networking.html
M B V R K
M B V R K11mo ago
I appreciate your time and help, I fixed it by changing the DI registration in program.cs to :
builder.Services.AddMassTransit(x => x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host("rabbitmq://localhost", hostConfig =>
{
hostConfig.Username("guest");
hostConfig.Password("guest");
});

cfg.ReceiveEndpoint(authServiceRabbitMqEndPoints.UserCreatedEventQueue, ep => ep.Consumer<UserCreatedMessageConsumer>(provider));

})));
builder.Services.AddMassTransit(x => x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host("rabbitmq://localhost", hostConfig =>
{
hostConfig.Username("guest");
hostConfig.Password("guest");
});

cfg.ReceiveEndpoint(authServiceRabbitMqEndPoints.UserCreatedEventQueue, ep => ep.Consumer<UserCreatedMessageConsumer>(provider));

})));
cap5lut
cap5lut11mo ago
glad ya found the issue o7 if this fully answers ur question please dont forget to $close this thread
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered