In the ABP framework, how to use the quorum queue of RabbitMQ?
I added a class that implements the IRabbitMqMessageConsumerFactory interface, like below, but it doesn't work.
Is there anything else I can try?
[ExposeServices(typeof(IRabbitMqMessageConsumerFactory))]
[Dependency(ReplaceServices = true)]
public class RabbitMqQuorumMessageConsumerFactory : RabbitMqMessageConsumerFactory
{
public RabbitMqQuorumMessageConsumerFactory(IServiceScopeFactory serviceScopeFactory) : base(
serviceScopeFactory)
{
}
public new IRabbitMqMessageConsumer Create(
ExchangeDeclareConfiguration exchange,
QueueDeclareConfiguration queue,
string connectionName = null)
{
const string quorumQueueType = "quorum";
const string queueTypeName = "x-queue-type";
var consumer = ServiceScope.ServiceProvider.GetRequiredService<RabbitMqMessageConsumer>();
if (queue.Arguments.ContainsKey(queueTypeName))
{
queue.Arguments.Remove(queueTypeName);
}
queue.Arguments.Add(queueTypeName, quorumQueueType);
consumer.Initialize(exchange, queue, connectionName);
return consumer;
}
}
In order to use the quorum queues, you'll need to cluster multiple nodes (at least 3) together. More info on the clustering can be found here: https://www.rabbitmq.com/clustering.html.
On the quorum queue page of RabbitMQ it also shows how many nodes you need for a specific fault tolerance (https://www.rabbitmq.com/quorum-queues.html):
So it isn't just setting the x-queue-type
to quorum, but actually connecting multiple nodes/machines together.
If you want to understand more about how quorum queues work, I'd suggest reading this link: https://www.cloudamqp.com/blog/quorum-queues-internals-a-deep-dive.html. It explains more about how the quorum queues actually work and how the Raft Consensus Algorithm works which RabbitMQ uses for Quorum Queues.
This is just a suggestion, but since you want to use quorum queues, it seems like you don't want to lose any messages. So I would take a look at Durable Queues and Persistent Messages