Basically, we are using MassTransit
with RabbitMQ
in out .Net
core application for publishing and consuming messages. We maintain 2 environments - dev
and demo
in the same server.
For this, we have created 2 virtual hosts dev and demo in RabbitMQ
and configured the dev vhost
to be used in dev environment and demo vhost
to be used in demo environment..
When we run the dev application, the service bus gets started and messages are correctly published and consumed. But in demo, the service bus is not started and the messages are not published or consumed. Need help to figure out a solution for this issue.
Ex. appsettings.json
for dev
application uses
"RabbitMqSettings": {
"Uri": "rabbitmq://localhost/dev",
"UserName": "guest",
"Password": "guest"
}
a
and for demo it is
"RabbitMqSettings": {
"Uri": "rabbitmq://localhost/demo",
"UserName": "guest",
"Password": "guest"
}
In the Program.cs
we have the configuration like below:
builder.Services.AddMassTransit(mt => mt.AddMassTransit(x => {
mt.AddConsumer<OrderCreatedConsumer>();
x.UsingRabbitMq((cntxt, cfg) => {
cfg.Host(uri, c => {
c.Username(rabbitMqSettings.UserName);
c.Password(rabbitMqSettings.Password);
});
cfg.ConfigureEndpoints(cntxt);
});
})
);
In dev logs, we could see below lines:
2024-04-26 13:34:06.9383|0|INFO|MassTransit|Configured endpoint OrderCreated, Consumer: OrderAPI.Services.OrderCreatedConsumer
2024-04-26 13:34:07.2920|0|INFO|MassTransit|Bus started: rabbitmq://localhost/dev
In Demo
logs, we could not see Bus Started information.
2024-04-27 13:34:06.9383|0|INFO|MassTransit|Configured endpoint OrderCreated, Consumer: OrderAPI.Services.OrderCreatedConsumer
Not sure why we are not getting the Bus Started information logged for Demo
..
Anyone got any idea on this? please help.
You need to give the user access to the virtual host, my guess is that you didn't.
Also, if you configure the host options properly you can set a StartTimeout
after which any errors connecting to the broker will be logged.
You should have seen a warning message in the logs if MassTransit was unable to connection, so, check your logs as well.