From 1502435942884b72f8901f8268dad1a9b345dc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 24 Mar 2021 19:21:02 +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/Producer.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Kafka/Producer.php b/Kafka/Producer.php index 072a6fee..0774e1b3 100644 --- a/Kafka/Producer.php +++ b/Kafka/Producer.php @@ -98,14 +98,18 @@ class Producer extends Component */ public function dispatch(string $topic, array $params = [], string $groupId = null) { - if ($groupId === null || empty($groupId)) { - $consumers = Config::get('kafka.consumers.' . $topic); - if (empty($consumers)) { - $consumers = ['groupId' => $topic . ':' . Snowflake::localhost()]; - } - $groupId = $consumers['groupId']; + $consumers = Config::get('kafka.consumers.' . $topic); + if (empty($consumers) || !is_array($consumers)) { + return; } - $this->setGroupId($groupId)->setTopic($topic)->delivery(swoole_serialize($params)); + + if (!empty($groupId)) { + $consumers['groupId'] = $groupId; + } else if (!isset($consumers['groupId'])) { + $consumers['groupId'] = $topic . ':' . Snowflake::localhost(); + } + $this->setGroupId($groupId)->setTopic($topic) + ->delivery(swoole_serialize($params)); }