jeudi 7 mars 2019

How to set listener queue name from environment variable?

I just noticed that some of my listeners do not use the queue I expected them to use. Our team upgraded from Laravel 5.2 to 5.5 a few weeks back, and I guess this is when the problem started happening. There hasn't been much load on the system, so I only discovered it by accident.

Anyway. I used to set the queue name on the listener through a queue method, like so:

public function queue(QueueManager $handler, $method, $arguments): void
{
    $handler->connection()->push($method, $arguments, Queue::getNotificationQueue());
}

This approach is not working anymore, so a default queue ends up handling the job instead of the expected notification queue.

So I looked at the documentation https://laravel.com/docs/5.5/events#queued-event-listeners, which states that the name should be set on a queue property on the listener. My problem is that I have the queue name in an environment variable, so I cannot just set it directly as a property, as shown in the documentation and it does not work to set it on the constructor, like so:

protected $queue;

public function __construct()
{
    $this->queue = Queue::getNotificationQueue();
}

Does anyone here have an idea of how I can get around this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire