laravel - Lumen Database Queued Event Listener 事件消失
问题描述
根据 Laravel 事件文档,我的印象是我可以通过在侦听器上添加“实现 ShouldQueue”来异步创建事件队列。
namespace App\Listeners;
use Log;
use App\Events\MeetEntryConfirmationEvent;
use App\Mail\MeetEntryConfirmation;
use Illuminate\Contracts\Queue\ShouldQueue;
class MeetEntryConfirmationListener implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param MeetEntryConfirmationEvent $event
* @return void
*/
public function handle(MeetEntryConfirmationEvent $entryEvent)
{
Log::debug('Attempt to send MeetEntryConfirmationEvent');
// Do time consuming stuff
}
}
我的事件是这样实现的:
class MeetEntryConfirmationEvent extends Event
{
use SerializesModels;
public $entry;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(MeetEntry $entry)
{
$this->entry = $entry;
Log::debug('Created MeetEntryConfirmationEvent');
}
}
我正在像这样派遣他们。
event(new MeetEntryConfirmationEvent($entry));
我已将 QUEUE_DRIVER 设置为数据库,作业表就在那里。当事件被调度时,它似乎工作正常,因为它立即返回。当我让它处于同步模式时,这项工作需要 8 秒,所以不再发生这种情况。
但是,作业表永远不会在其中获得一行,并且当我运行队列工作者时,没有任何反应,作业不会执行。
我也尝试将 config/queue.php 从 Laravel 复制到我的 lumen 应用程序中,但这似乎没有什么不同。当它在同步驱动程序中并且当我不使用 ShouldQueue 时,确实会发生这项工作。
解决方案
所以我最终发现了问题。它归结为 Lumen/Laravel 手册中没有的细节。
您需要将其添加到服务提供者注册部分的 Lumen 引导程序中:
$app->configure('queue');
$app->register(Illuminate\Queue\QueueServiceProvider::class);
推荐阅读
- gulp - 使用 Gulp Rename 从文件名中删除空格
- string - 如何查找字符串中最后一次出现的字符?
- jenkins - 在 kubernetes 中使用 Jenkins 和 Deployment 构建特定于租户的 docker 镜像
- typo3 - Typo3:将所有 2 级页面输出为独立于活动页面的菜单
- kotlin - KClass::memberExtensionFunctions 始终为空
- go - 在 goroutine 中添加处理程序时如何防止数据竞争?
- c# - Xceed DocX 如何在生成的 Word 文档中创建索引
- c# - 实现 IQueryable 和 AST 以在游戏中查找实体
- css - jQuery UI 小部件 CSS 继承问题
- php - 智能卡外部身份验证 6982 错误