This commit is contained in:
2020-10-09 11:27:00 +08:00
parent 01b5a437a8
commit b5e8eeed91
3 changed files with 954 additions and 949 deletions
+41 -39
View File
@@ -14,21 +14,23 @@
namespace Kafka\Consumer; namespace Kafka\Consumer;
/** use Swoole\Timer;
+------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8
+------------------------------------------------------------------------------
*
* @package
* @version $_SWANBR_VERSION_$
* @copyright Copyleft
* @author $_SWANBR_AUTHOR_$
+------------------------------------------------------------------------------
*/
/**
* +------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8
* +------------------------------------------------------------------------------
*
* @package
* @version $_SWANBR_VERSION_$
* @copyright Copyleft
* @author $_SWANBR_AUTHOR_$
* +------------------------------------------------------------------------------
*/
class State class State
{ {
use \Kafka\SingletonTrait; use \Kafka\SingletonTrait;
// {{{ consts // {{{ consts
const REQUEST_METADATA = 1; const REQUEST_METADATA = 1;
@@ -81,31 +83,31 @@ class State
{ {
$this->callStatus = array( $this->callStatus = array(
self::REQUEST_METADATA => array( self::REQUEST_METADATA => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_GETGROUP => array( self::REQUEST_GETGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_JOINGROUP => array( self::REQUEST_JOINGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_SYNCGROUP => array( self::REQUEST_SYNCGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_HEARTGROUP => array( self::REQUEST_HEARTGROUP => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_OFFSET => array( self::REQUEST_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_FETCH => array( self::REQUEST_FETCH => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_FETCH_OFFSET => array( self::REQUEST_FETCH_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_COMMIT_OFFSET => array( self::REQUEST_COMMIT_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
); );
@@ -134,13 +136,13 @@ class State
continue; continue;
} }
$interval = isset($option['interval']) ? $option['interval'] : 200; $interval = isset($option['interval']) ? $option['interval'] : 200;
\Amp\repeat(function ($watcherId) use ($request, $option) { Timer::tick($msInterval = $interval, function ($watcherId) use ($request, $option) {
if ($this->checkRun($request) && $option['func'] != null) { if ($this->checkRun($request) && $option['func'] != null) {
$context = call_user_func($option['func']); $context = call_user_func($option['func']);
$this->processing($request, $context); $this->processing($request, $context);
} }
$this->requests[$request]['watcher'] = $watcherId; $this->requests[$request]['watcher'] = $watcherId;
}, $msInterval = $interval); });
} }
// start sync metadata // start sync metadata
@@ -148,9 +150,9 @@ class State
$context = call_user_func($this->requests[self::REQUEST_METADATA]['func']); $context = call_user_func($this->requests[self::REQUEST_METADATA]['func']);
$this->processing($request, $context); $this->processing($request, $context);
} }
\Amp\repeat(function ($watcherId) { Timer::tick($msInterval = 1000, function ($watcherId) {
$this->report(); $this->report();
}, $msInterval = 1000); });
} }
// }}} // }}}
@@ -250,25 +252,25 @@ class State
self::REQUEST_METADATA => $this->callStatus[self::REQUEST_METADATA], self::REQUEST_METADATA => $this->callStatus[self::REQUEST_METADATA],
self::REQUEST_GETGROUP => $this->callStatus[self::REQUEST_GETGROUP], self::REQUEST_GETGROUP => $this->callStatus[self::REQUEST_GETGROUP],
self::REQUEST_JOINGROUP => array( self::REQUEST_JOINGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_SYNCGROUP => array( self::REQUEST_SYNCGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_HEARTGROUP => array( self::REQUEST_HEARTGROUP => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_OFFSET => array( self::REQUEST_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_FETCH => array( self::REQUEST_FETCH => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_FETCH_OFFSET => array( self::REQUEST_FETCH_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_COMMIT_OFFSET => array( self::REQUEST_COMMIT_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
); );
} }
@@ -281,28 +283,28 @@ class State
$this->callStatus = array( $this->callStatus = array(
self::REQUEST_METADATA => $this->callStatus[self::REQUEST_METADATA], self::REQUEST_METADATA => $this->callStatus[self::REQUEST_METADATA],
self::REQUEST_GETGROUP => array( self::REQUEST_GETGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_JOINGROUP => array( self::REQUEST_JOINGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_SYNCGROUP => array( self::REQUEST_SYNCGROUP => array(
'status'=> self::STATUS_START, 'status' => self::STATUS_START,
), ),
self::REQUEST_HEARTGROUP => array( self::REQUEST_HEARTGROUP => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_OFFSET => array( self::REQUEST_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_FETCH => array( self::REQUEST_FETCH => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_FETCH_OFFSET => array( self::REQUEST_FETCH_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_COMMIT_OFFSET => array( self::REQUEST_COMMIT_OFFSET => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
); );
} }
+14 -13
View File
@@ -14,18 +14,19 @@
namespace Kafka\Producer; namespace Kafka\Producer;
/** use Swoole\Timer;
+------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8
+------------------------------------------------------------------------------
*
* @package
* @version $_SWANBR_VERSION_$
* @copyright Copyleft
* @author $_SWANBR_AUTHOR_$
+------------------------------------------------------------------------------
*/
/**
* +------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8
* +------------------------------------------------------------------------------
*
* @package
* @version $_SWANBR_VERSION_$
* @copyright Copyleft
* @author $_SWANBR_AUTHOR_$
* +------------------------------------------------------------------------------
*/
class Process class Process
{ {
use \Psr\Log\LoggerAwareTrait; use \Psr\Log\LoggerAwareTrait;
@@ -110,13 +111,13 @@ class Process
$config = \Kafka\ProducerConfig::getInstance(); $config = \Kafka\ProducerConfig::getInstance();
$isAsyn = $config->getIsAsyn(); $isAsyn = $config->getIsAsyn();
if (!$isAsyn) { if (!$isAsyn) {
\Amp\repeat(function ($watcherId) { Timer::tick($msInterval = $config->getRequestTimeout(), function ($watcherId) {
if ($this->error) { if ($this->error) {
call_user_func($this->error, 1000); call_user_func($this->error, 1000);
} }
\Amp\cancel($watcherId); \Amp\cancel($watcherId);
\Amp\stop(); \Amp\stop();
}, $msInterval = $config->getRequestTimeout()); });
}; };
} }
+20 -18
View File
@@ -14,21 +14,23 @@
namespace Kafka\Producer; namespace Kafka\Producer;
/** use Swoole\Timer;
+------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8
+------------------------------------------------------------------------------
*
* @package
* @version $_SWANBR_VERSION_$
* @copyright Copyleft
* @author $_SWANBR_AUTHOR_$
+------------------------------------------------------------------------------
*/
/**
* +------------------------------------------------------------------------------
* Kafka protocol since Kafka v0.8
* +------------------------------------------------------------------------------
*
* @package
* @version $_SWANBR_VERSION_$
* @copyright Copyleft
* @author $_SWANBR_AUTHOR_$
* +------------------------------------------------------------------------------
*/
class State class State
{ {
use \Kafka\SingletonTrait; use \Kafka\SingletonTrait;
// {{{ consts // {{{ consts
const REQUEST_METADATA = 1; const REQUEST_METADATA = 1;
@@ -59,10 +61,10 @@ class State
{ {
$this->callStatus = array( $this->callStatus = array(
self::REQUEST_METADATA => array( self::REQUEST_METADATA => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
self::REQUEST_PRODUCE => array( self::REQUEST_PRODUCE => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
); );
@@ -93,13 +95,13 @@ class State
{ {
foreach ($this->requests as $request => $option) { foreach ($this->requests as $request => $option) {
$interval = isset($option['interval']) ? $option['interval'] : 200; $interval = isset($option['interval']) ? $option['interval'] : 200;
\Amp\repeat(function ($watcherId) use ($request, $option) { Timer::tick($msInterval = $interval, function ($watcherId) use ($request, $option) {
if ($this->checkRun($request) && $option['func'] != null) { if ($this->checkRun($request) && $option['func'] != null) {
$context = call_user_func($option['func']); $context = call_user_func($option['func']);
$this->processing($request, $context); $this->processing($request, $context);
} }
$this->requests[$request]['watcher'] = $watcherId; $this->requests[$request]['watcher'] = $watcherId;
}, $msInterval = $interval); });
} }
// start sync metadata // start sync metadata
@@ -108,9 +110,9 @@ class State
$context = call_user_func($this->requests[self::REQUEST_METADATA]['func']); $context = call_user_func($this->requests[self::REQUEST_METADATA]['func']);
$this->processing($request, $context); $this->processing($request, $context);
} }
\Amp\repeat(function ($watcherId) { Timer::tick($msInterval = 1000, function ($watcherId) {
$this->report(); $this->report();
}, $msInterval = 1000); });
} }
// }}} // }}}
@@ -192,7 +194,7 @@ class State
$this->callStatus = array( $this->callStatus = array(
self::REQUEST_METADATA => $this->callStatus[self::REQUEST_METADATA], self::REQUEST_METADATA => $this->callStatus[self::REQUEST_METADATA],
self::REQUEST_PRODUCE => array( self::REQUEST_PRODUCE => array(
'status'=> self::STATUS_LOOP, 'status' => self::STATUS_LOOP,
), ),
); );
} }