Have a newbie question about Mass Transit ESB
I am trying MassTransit for the first time and trying to get my head around how the queues are created and how messages are consumed.
I have a web application and a Console application trying to do publish / consume respectively
This is my initialization code.
var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
{
var host = sbc.Host(new Uri(hostName), h =>
{
h.Username(userName);
h.Password(password);
});
});
Then from the web app i call the following code.
using (Bus.Start())
{
var pubr = Bus.Publish<T>(message);
pubr.Wait();
}
This leads to the message being lost in Rabbit MQ .
I can get the sample to work if I add a consumer in the console application.
sbc.ReceiveEndpoint(host,
e =>
e.Consumer<LoginEventConsumer>(d => { })
{ }
My question is why does my message get lost if there are no consumers ?
It looks like Rabbit MQ believes that there is no queue connected to the exchange and hence the message is lost . Is that correct ? Is there a way to create queues and exchange together during initialization without cluttering Rabbit MQ with lots of randomly named queues / exchanges ?
Looks like i am missing something very basic in my understanding of how MassTransit / Rabbit MQ works. I would have thought its a very common scenario that a consumer registration happens at a later point than the publish event and that the consumer will be sent all the items that have been published once it connects .