在Laravel中如何创建队列对象并设置其连接而无需Facade [英] In Laravel how to create a queue object and set their connection without Facade

查看:72
本文介绍了在Laravel中如何创建队列对象并设置其连接而无需Facade的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lumen/Laravel中,我想向给定队列发送消息.

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

默认情况下,我将其设置为Redis,我希望将其发送到另一个队列服务器,因为另一个应用程序会处理它.

by default I have it set to Redis, what I would like is to send it to another queue server as another application will take care of it.

我知道我可以$queue->pushRaw('payload');,但是我没有后续的选择方法.

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

我知道我可以使用Facade这样创建队列:

I am aware that I can use Facade to create my Queue as such:

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

但是,我正在流明中进行此操作,并希望避免仅针对此方面打开外观".另外,我想知道如何执行此操作,因为我想最终通过作业事件处理程序将IoC传递给我.

However I'm doing this in Lumen, and would like to avoid turning on the Facade Just for this aspect. Also, I would like to know how to do this as I would like to pass by IoC through a job event handler eventually.

Lumen/Laravel 5.2的版本.

Version of Lumen/Laravel 5.2.

推荐答案

正如@ Mois44所暗示的那样,您应该能够使用QueueManager来完成此任务.

As @Mois44 alluded to, you should be able to accomplish this with the QueueManager.

QueueManager将允许您调用connection()方法,该方法将返回Queue对象.从这里,您可以调用普通的排队函数(pushOn,latereOn等)

The QueueManager will allow you to call the connection() method, which will return a Queue object. And from here, you can call the normal queued functions (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);

或全部链接在一起

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


诚然,我对流明的了解非常有限.如果app()方法无法获取QueueMananger的实例,那么我不确定该怎么办.


Admittedly, my Lumen specific knowledge is pretty limited. If the app() method doesn't work to get an instance of the QueueMananger, then I'm not sure what to do.

这篇关于在Laravel中如何创建队列对象并设置其连接而无需Facade的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆