ssi-anik / amqp

php-amqplib wrapper that eases the consumption of RabbitMQ. A painless way of using RabbitMQ
https://packagist.org/packages/anik/amqp
MIT License
134 stars 23 forks source link

How to define multiple queues for consuming #6

Closed sujit-baniya closed 4 years ago

sujit-baniya commented 4 years ago

Hello,

I'm using following code for consuming a queue:

$connection = $this->argument('connection') ?? config('amqp.default');
        app('amqp')->consume(function (ConsumableMessage $message) {
            $msg = json_decode($message->getStream(), true);
            $job = unserialize($msg['data']['command']);
            $throttleExceeded = $job->handle();
            if ($throttleExceeded === 'throttle exceeded')
            {
                $message->getDeliveryInfo()->reject(true);
            } else {
                $message->getDeliveryInfo()->acknowledge();
            }
        }, 'routing-key', [
            'connection' => $connection,
            'exchange' => [
                'type' => 'direct',
                'name' => $this->option('exchange'),
            ],
            'queue' => [
                'name' => $this->option('queue'),
                'declare' => true,
                'exclusive' => false,
            ],
            'qos' => [
                'enabled' => true,
                'qos_prefetch_count' => $this->option('prefetch_count'),
            ],
        ]);

I can run consume one queue without any issue. I want to consume multiple queues. How could I do so?

ssi-anik commented 4 years ago

@itsursujit sorry to reply this late. For now, there is no way to consume multiple queues at a time. And if your multiple queues are handled by the same closure then you can make two instances of the command, IMO.