1

I have a rabbit consumer that works fine (it correctly processes messages, sends acks, etc.).

In it, I am trying to check if a queue is empty using the queue_declare and passive flag (as suggested here: RabbitMQ - How to check if queue is empty?).

The relevant part of the code looks like this:

  <?php
      $a = $this->channel->queue_declare($queueName, true);
      var_dump($a);

My problem is that it always returns (regardless on how many messages are on queue - I tested with like 1000):

    array(3) {
      [0]=>
        string(4) "fastQueue"
      [1]=>
        int(0)
      [2]=>
        int(1)
    }

Any idea why?

zozo
  • 8,230
  • 19
  • 79
  • 134
  • What PHP library are you using? What version of RabbitMQ and Erlang? Could you provide a complete set of code to reproduce? – Luke Bakken Feb 21 '19 at 15:15
  • Typically the size of a queue is not relevant to the consumers of the queue - this indicates poor system design. However, there is a management API which can be used to return queue size, if that is indeed what you are looking for. – theMayer Feb 21 '19 at 16:19
  • @LukeBakken I'm using lates RabbitMQ, https://github.com/php-amqplib/php-amqplib as lib and... I'll get back to you with Erlang version (I am on phone atm). – zozo Feb 22 '19 at 08:27
  • @theMayer I don't really care about the size of the queue, I just care if is empty or not because I don't wanna keep the connection open if there is nothing on queues (if you can explain why this would be poor system design I would appreciate it). Also in the future I actually was thinking to check queue size and spawn additional consumers / raise processes priorities for spikes (again, why would that be poor system design - no sarcasm, I'm genuinely asking). – zozo Feb 22 '19 at 08:35
  • 1
    `Basic.Get` is what you’re looking for. It returns immediately whether there is a message available or not. – theMayer Feb 22 '19 at 12:46

0 Answers0