laravel5.5 使用event 和listener 执行列队 ShouldQueue 同反应?

在controller上面

$user = DB::table('users')->where('id',2)->first();
event(new NotifyEvent($user));

在 EventServiceProvider 上面设置

protected $listen = [
        'App\Events\NotifyEvent' => [
            'App\Listeners\NotifyListener', 
            'App\Listeners\NotifyCardListener',
        ],
    ];

NotifyCardListener 这个是没有列队 直接就

public function handle(NotifyEvent $event)
    {
        var_dump($event->user);
    }

NotifyListener 这个是加了 列队

class NotifyListener implements ShouldQueue
{
    /**
     * 任务应该发送到的队列的连接的名称
     *
     * @var string|null
     */
    public $connection = 'redis';

    /**
     * 任务应该发送到的队列的名称
     *
     * @var string|null
     */
    public $queue = 'listeners';

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  NotifyEvent  $event
     * @return void
     */
    public function handle(NotifyEvent $event)
    {
        Log::info(json_encode($event->user));
    }
}

然后运行 php artisan queue:work

访问上面的controller

然后输入成功,但是 php artisan queue:work 没有任何反应。
然后看redis
image.png

有数据插入

请问这是为什么??

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题