你好,开发人员,
我尝试使用This Question中的解决方案,但是它不能解决我的问题,因此我将其作为一个单独的问题来询问。
TL;DR
-我希望我的订阅服务器侦听器在队列中异步执行。我的订户为每个事件从不同的类调用方法。我试图在我的SubscriberClass中添加implements ShouldQueue
。我的侦听器类|在每个类中将方法重命名为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));
帮助我了解我在做错什么。