In Laravel, how to create a queue object and establish their connection without Facade

In Lumen / Laravel I want to send a message to a given queue.

by default I installed it in Redis, I would like to send it to another queue server, as this will take care of another application.

I know I can do $queue->pushRaw('payload'); However, for me there is no subsequent way to select a connection.

I know that I can use Facade to create my queue as such:

 $connection = Queue::connection('connection_name'); $connection->pushOn('queue_name', $job) 

However, I do this in Lumen, and would like not to include the Facade for this aspect only. In addition, I would like to know how to do this, as I would like to go through IoC through the job event handler.

Version Lumen / Laravel 5.2.

+5
source share
1 answer

As reported by @ Mois44, you must accomplish this using QueueManager.

QueueManager allows you to call the connection () method, which will return a Queue object. And from here you can call ordinary functions in the queue (pushOn, laterOn, etc.)

 // Returns an Illuminate\Queue\QueueManager object $queueManager = app('queue'); // Returns an Illuminate\Queue\Queue object $queue = $queueManager->connection('my-connection'); $queue->pushOn('queue_name', $job); 

or all bonded together

 app('queue')->connection('my-connection')->pushOn('queue_name', $job) 

Admittedly, my specific knowledge of Lumen is quite limited. If the app () method does not work to get an instance of QueueManager, I'm not sure what to do.

+2
source

All Articles