This commit is contained in:
2020-10-09 19:21:02 +08:00
parent eebc23da5b
commit 0e722df943
+54 -53
View File
@@ -18,66 +18,67 @@ use function Amp\run;
/** /**
* +------------------------------------------------------------------------------ * +------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8 * Kafka protocol since Kafka v0.8
* +------------------------------------------------------------------------------ * +------------------------------------------------------------------------------
* *
* @package * @package
* @version $_SWANBR_VERSION_$ * @version $_SWANBR_VERSION_$
* @copyright Copyleft * @copyright Copyleft
* @author $_SWANBR_AUTHOR_$ * @author $_SWANBR_AUTHOR_$
* +------------------------------------------------------------------------------ * +------------------------------------------------------------------------------
*/ */
class Consumer class Consumer
{ {
use \Psr\Log\LoggerAwareTrait; use \Psr\Log\LoggerAwareTrait;
use \Kafka\LoggerTrait; use \Kafka\LoggerTrait;
// {{{ consts // {{{ consts
// }}} // }}}
// {{{ members // {{{ members
private $isRunning = false; private $isRunning = false;
// }}} // }}}
// {{{ functions // {{{ functions
// {{{ public function __construct() // {{{ public function __construct()
/** /**
* __construct * __construct
* *
* @access public * @access public
* @param $hostList * @param $hostList
* @param null $timeout * @param null $timeout
*/ */
public function __construct() public function __construct()
{ {
} }
// }}} // }}}
// {{{ public function start() // {{{ public function start()
/** /**
* start consumer * start consumer
* *
* @access public * @access public
* @return void * @return void
*/ */
public function start(\Closure $consumer = null, $isBlock = true) public function start(\Closure $consumer = null, $isBlock = true)
{ {
if ($this->isRunning) { if ($this->isRunning) {
$this->error('Has start consumer'); $this->error('Has start consumer');
return; return;
} }
$process = new \Kafka\Consumer\Process($consumer); $process = new \Kafka\Consumer\Process($consumer);
if ($this->logger) { if ($this->logger) {
$process->setLogger($this->logger); $process->setLogger($this->logger);
} }
$process->start(); $process->start();
$this->isRunning = true; $this->isRunning = true;
run(); if ($isBlock) {
} run();
}
}
// }}} // }}}
// }}} // }}}
} }