This commit is contained in:
2020-10-12 12:54:19 +08:00
parent ffc8f5db54
commit 0a9be5595a
+3 -10
View File
@@ -72,7 +72,7 @@ class Kafka extends \Snowflake\Process\Process
$group->add(); $group->add();
go(function () use ($group) { go(function () use ($group) {
while ([$topic, $part, $message] = $this->channel->pop()) { while ([$topic, $part, $message] = $this->channel->pop()) {
$this->handlerExecute($group, $topic, $part, $message); $this->handlerExecute($topic, $part, $message);
} }
}); });
} }
@@ -82,12 +82,11 @@ class Kafka extends \Snowflake\Process\Process
/** /**
* @param $group
* @param $topic * @param $topic
* @param $part * @param $part
* @param $message * @param $message
*/ */
protected function handlerExecute($group, $topic, $part, $message) protected function handlerExecute($topic, $part, $message)
{ {
try { try {
$namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer'; $namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer';
@@ -98,13 +97,7 @@ class Kafka extends \Snowflake\Process\Process
if (!($class instanceof ConsumerInterface)) { if (!($class instanceof ConsumerInterface)) {
return; return;
} }
$group->add(); $class->onHandler(new Struct($topic, $part, $message));
go(function () use ($group, $class, $topic, $part, $message) {
defer(function () use ($group) {
$group->done();
});
$class->onHandler(new Struct($topic, $part, $message));
});
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->application->error($exception->getMessage()); $this->application->error($exception->getMessage());
} }