This commit is contained in:
2020-10-10 11:31:23 +08:00
parent bc8905c863
commit bfc507782d
+23 -21
View File
@@ -63,29 +63,31 @@ class Kafka extends \Snowflake\Process\Process
*/
public function initCoroutine()
{
$group = new WaitGroup();
while ([$topic, $part, $message] = $this->channel->pop()) {
try {
$namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer';
if (!class_exists($namespace)) {
return;
}
$class = Snowflake::createObject($namespace);
if (!($class instanceof ConsumerInterface)) {
continue;
}
$group->add();
go(function () use ($group, $class, $topic, $part, $message) {
defer(function () use ($group) {
$group->done();
go(function () {
$group = new WaitGroup();
while ([$topic, $part, $message] = $this->channel->pop()) {
try {
$namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer';
if (!class_exists($namespace)) {
return;
}
$class = Snowflake::createObject($namespace);
if (!($class instanceof ConsumerInterface)) {
continue;
}
$group->add();
go(function () use ($group, $class, $topic, $part, $message) {
defer(function () use ($group) {
$group->done();
});
$class->onHandler(new Struct($topic, $part, $message));
});
$class->onHandler(new Struct($topic, $part, $message));
});
} catch (\Throwable $exception) {
$this->application->error($exception->getMessage());
} catch (\Throwable $exception) {
$this->application->error($exception->getMessage());
}
}
}
$group->wait();
$group->wait();
});
}