Search code examples
rabbitmqphp-amqplib

How to stop Rabbitmq Consumer after processing 10 messages?


I was running consumer from crontab and it processing all the messages one by one, Is there any way to consume only 10 or 20 messages and then stop to consumer.

So next time cron will call to consumer and same process will happen again.


Solution

  • You can use synchronous basic.get method. Wrap it in a for loop or add sort of a counter. And quite the app once you reach desired number.

    This method provides a direct access to the messages in a queue using a synchronous dialogue that is designed for specific types of application where synchronous functionality is more important than performance.