From 5791a90b5c5241156fff7567daad96293c233d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Oct 2020 18:44:49 +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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Kafka/Kafka.php b/Kafka/Kafka.php index e0ab0a1a..64385faf 100644 --- a/Kafka/Kafka.php +++ b/Kafka/Kafka.php @@ -134,7 +134,15 @@ class Kafka extends \Snowflake\Process\Process $conf = new Conf(); $kafka = SConfig::get('kafka'); - $conf->setRebalanceCb([$this, 'rebalanced_cb']); + $conf->setRebalanceCb(function (KafkaConsumer $kafka, $err, array $partitions = null) { + if ($err == RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS) { + $kafka->assign($partitions); + } else if ($err == RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS) { + $kafka->assign(NULL); + } else { + throw new \Exception($err); + } + }); $conf->set('group.id', uniqid('kafka')); $conf->set('metadata.broker.list', '127.0.0.1:9092');