I have added a Received Event Handler of EventingBasicConsumer in RabbitMQ. I am trying to check if the Queue is consumed(processed and now empty), It should Close the consumer and connection. I am not able to find the condition which can tell if the Queue is processed.
Please help
public void ProcessQueue(string queueName, Func<string, bool> ProcessMessage)
{
//lock (this.Model)
{
this.Model.BasicQos(0, 1, false);
EventingBasicConsumer consumer = new EventingBasicConsumer(this.Model);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
bool processed = ProcessMessage.Invoke(message);
if (processed)
this.SendAcknowledgement(ea.DeliveryTag);
else
this.StopProcessingQueue(consumer.ConsumerTag);
// Check if no message for next 2 minutes,
// Stop Consumer and close connection
};
this.Model.BasicConsume(queue: queueName,
autoAck: false,
consumer: consumer);
}
}