4

您好优秀的开发人员,

我尝试使用This Question中的解决方案,但它没有解决我的问题,因此我将其作为一个单独的问题提出。

TL;DR- 我希望我的订阅者监听器在队列中异步执行。我的订阅者为每个事件调用不同类的方法。我试图添加implements ShouldQueue我的 SubscriberClass | 我的听众班 | 将方法重命名为handle在每个类中,但没有任何效果。它们仍然在没有队列的情况下同步执行。

我有一个事件订阅者类:TesterAPI. 我将它添加到EventServiceProvider subscribe数组中。

我有一个事件类SourceAPIEvents

class SourceAPIEvents
{
    const PROJECT_CREATED = 'project.created';
    const PROJECT_PAUSED = 'project.paused';
    const PROJECT_RESUME = 'project.resume';
    const PROJECT_CLOSED = 'project.closed';

    public $project;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Project $project)
    {
        $this->project = $project;
    }
}

TesterAPI- 订户

class TesterAPI implements ShouldQueue
{

    /**
     * Register the listeners for the subscriber.
     *
     * @param \Illuminate\Events\Dispatcher $events
     */
    public function subscribe($events)
    {
        $events->listen(
            SourceAPIEvents::PROJECT_CREATED,
            'App\Listeners\Internal\Project\SourceAPI\Tester\ProjectCreate@handle'
        );

        $events->listen(
            SourceAPIEvents::PROJECT_RESUME,
            'App\Listeners\Internal\Project\SourceAPI\Tester\ProjectResume@handle'
        );

        $events->listen(
            SourceAPIEvents::PROJECT_PAUSED,
            'App\Listeners\Internal\Project\SourceAPI\Tester\ProjectPause@handle'
        );

        $events->listen(
            SourceAPIEvents::PROJECT_CLOSED,
            'App\Listeners\Internal\Project\SourceAPI\Tester\ProjectClose@handle'
        );
    }
}

这是我的听众课程:

class ProjectCreate extends TesterBase implements ShouldQueue
{
    public function handle(SourceAPIEvents $sourceAPIEvent)
    {
        //Do Something
    }

}

class ProjectPause extends TesterBase implements ShouldQueue
{
    public function handle(SourceAPIEvents $sourceAPIEvent)
    {
        //Do Something
    }

}

class ProjectResume extends TesterBase implements ShouldQueue
{
    public function handle(SourceAPIEvents $sourceAPIEvent)
    {
        //Do Something
    }

}

我这样称呼这些事件

event(SourceAPIEvents::PROJECT_CREATED, new SourceAPIEvents($project));

event(SourceAPIEvents::PROJECT_RESUME, new SourceAPIEvents($project));

帮助我了解我做错了什么。

4

0 回答 0