【问题标题】:Lumen Database Queued Event Listener event disappearsLumen Database Queued Event Listener 事件消失
【发布时间】:2020-02-08 08:27:53
【问题描述】:

根据 Laravel 事件文档,我的印象是我可以通过在侦听器上添加“implements 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 时,确实会发生这项工作。

【问题讨论】:

  • 旁注:您是否在顶部的侦听器中为该事件起别名?
  • 嗯,我不确定你的意思是什么?
  • use App\Events\MeetEntryConfirmationEvent; 类似的东西
  • 是的,我有这些。我刚刚编辑添加了它。

标签: laravel lumen


【解决方案1】:

所以我最终找到了问题所在。它归结为 Lumen/Laravel 手册中没有的细节。

您需要将此添加到 Lumen 引导程序中的服务提供商注册部分:

$app->configure('queue');
$app->register(Illuminate\Queue\QueueServiceProvider::class);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-02
    • 2015-07-03
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多