Search code examples
rabbitmqmasstransit

Creating quorum queues by Sender in RabbitMQ by MassTransit


I use MassTransit and RabbitMQ quorum queue for application integration. I send message using

var endpoint = await _bus.GetSendEndpoint(new Uri("exchange:TestCommand"));
await endpoint.Send(command1, stoppingToken);

If "receiver application" doesn't ever start, queue won't be created and all sent messages will be lost.

If I use prefix queue for send:

var endpoint = await _bus.GetSendEndpoint(new Uri("queue:TestCommand"));
await endpoint.Send(command, stoppingToken);

classic queue will be created (not quorum). And I can't change queue type later.

I don't want to think about "receiver application" starting moment and I don't want to loose sent messages. How I can create RabbitMQ quorum queue by sender application using MassTransit?


Solution

  • The general guidance is simple, don't couple your producers to your consumers.

    You can start the receiver first so that it configures the queue properly (including the quorum settings).

    Or you can set the Mandatory flag (RabbitMQ specified) so that Send throws an exception if the message is not delivered to a queue, and return to sending to the exchange.