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() public function initCoroutine()
{ {
$group = new WaitGroup(); go(function () {
while ([$topic, $part, $message] = $this->channel->pop()) { $group = new WaitGroup();
try { while ([$topic, $part, $message] = $this->channel->pop()) {
$namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer'; try {
if (!class_exists($namespace)) { $namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer';
return; if (!class_exists($namespace)) {
} return;
$class = Snowflake::createObject($namespace); }
if (!($class instanceof ConsumerInterface)) { $class = Snowflake::createObject($namespace);
continue; if (!($class instanceof ConsumerInterface)) {
} continue;
$group->add(); }
go(function () use ($group, $class, $topic, $part, $message) { $group->add();
defer(function () use ($group) { go(function () use ($group, $class, $topic, $part, $message) {
$group->done(); 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(); });
} }