From 2c77e30ca29e849335c02947053b7167772bdb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 12 Jan 2021 17:36:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Kafka/Kafka.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Kafka/Kafka.php b/Kafka/Kafka.php index 92f99307..cb8f72db 100644 --- a/Kafka/Kafka.php +++ b/Kafka/Kafka.php @@ -118,21 +118,23 @@ class Kafka extends \Snowflake\Process\Process */ protected function handlerExecute($topic, $message) { - try { - $topic = str_replace('-', '_', $topic); + go(function () use ($topic, $message) { + try { + $topic = str_replace('-', '_', $topic); - $namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer'; - if (!class_exists($namespace)) { - return; + $namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer'; + if (!class_exists($namespace)) { + return; + } + $class = Snowflake::createObject($namespace); + if (!($class instanceof ConsumerInterface)) { + return; + } + $class->onHandler(new Struct($topic, $message)); + } catch (Throwable $exception) { + $this->application->error($exception->getMessage()); } - $class = Snowflake::createObject($namespace); - if (!($class instanceof ConsumerInterface)) { - return; - } - $class->onHandler(new Struct($topic, $message)); - } catch (Throwable $exception) { - $this->application->error($exception->getMessage()); - } + }); }