0

Is there's a way in RabbitMQ to route messages in the queue when it has no consumer to another queue. I'm thinking about using mixture of ttl and deadletter exchange so if messages exceeds some period of time the message will be expired and routed to deadletter exchange. Although that solution will work but it has a risk that even the queue has consumers, messages can be expired if they exceed that expiry time because of high load.

so is there a better way to achieve that?

or a way to ensure the queue has consumers before publishing to it.

1 Answers1

0

I found that we can check the number of consumer on that queue using IModel.QueueDeclarePassive(string queue) method which return QueueDeclareOk as following

QueueDeclareOk result = _channel.QueueDeclarePassive(queueName);
if (result.ConsumerCount == 0)
{
    // publish to another queue or whatever you want
}