From 27aad767a240dd5dc75b1a5f8bd4f2ad954ffdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 28 Oct 2020 16:38:05 +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 | 15 +++++---------- System/Event.php | 5 +++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Kafka/Producer.php b/Kafka/Producer.php index b44d5da2..b9cd8229 100644 --- a/Kafka/Producer.php +++ b/Kafka/Producer.php @@ -109,22 +109,17 @@ class Producer extends Component $rk->flush($timeout); $event = Snowflake::app()->getEvent(); - $event->on(Event::EVENT_AFTER_REQUEST, function ($rk, $timeout) { - var_dump(func_get_args()); - }, [$rk, $timeout]); + $event->on(Event::EVENT_AFTER_REQUEST, [$this,'onFlush'], [$rk, $timeout]); } /** - * @throws NotFindClassException - * @throws ReflectionException + * @param $rk + * @param $timeout */ - public function onFlush() + public function onFlush($rk, $timeout) { - /** @var \RdKafka\Producer $rk */ - $rk = Snowflake::getDi()->get(\RdKafka\Producer::class); - $this->debug(Event::EVENT_AFTER_REQUEST); - $rk->flush(10); + $rk->flush($timeout); } } diff --git a/System/Event.php b/System/Event.php index d9e7d5d2..e049c8c9 100644 --- a/System/Event.php +++ b/System/Event.php @@ -14,9 +14,9 @@ use Snowflake\Core\ArrayAccess; class Event extends BaseObject { - public $isVide = true; + public bool $isVide = true; - private $_events = []; + private array $_events = []; const EVENT_ERROR = 'WORKER:ERROR'; const EVENT_STOP = 'WORKER:STOP'; @@ -191,6 +191,7 @@ class Event extends BaseObject return $result; } foreach ($this->_events[$name] as $event) { + var_dump($event); [$handler, $defaultParameter] = $event; try { if (!empty($parameter)) {