snatch-dev/Convey

[RabbitMQ] Declare Quorum Queues

Opened this issue · 2 comments

Is there any way of declare a queue as a Quorum Queue in order to be used on a K8s cluster with multiple replicas?

Currently I don't see any way of adding additional arguments to the queue declaration (in QueueOptions). Maybe is something to be added?

spetz commented

That's a good idea - will check what can be done, and extend the implementation.

pretty easy to do.

I extended the RabbitMqOptions.QueueOptions:

public class QueueOptions
    {
        public string Template { get; set; }
        public bool Declare { get; set; }
        public bool Durable { get; set; }
        public bool Exclusive { get; set; }
        public bool AutoDelete { get; set; }
        public Dictionary<string, object> Arguments { get; set; }
    }

Updated RabbitMqBackgroundService.Subscribe:

var queueArguments = deadLetterEnabled
    ? new Dictionary<string, object>
    {
        {"x-dead-letter-exchange", deadLetterExchange},
        {"x-dead-letter-routing-key", deadLetterQueue},
    }
    : new Dictionary<string, object>();

// additional arguments
if (_options.Queue.Arguments != null)
{
    foreach (var key in _options.Queue.Arguments)
    {
        queueArguments.TryAdd(key.Key, key.Value);
    }
}

channel.QueueDeclare(conventions.Queue, durable, exclusive, autoDelete, queueArguments);

Updated appsettings to pass in the quorum queue arguments:

"rabbitMq": {
  "queue": {
    "arguments": {
      "x-queue-type": "quorum"
    }
  }
}