改名
This commit is contained in:
+26
-15
@@ -58,9 +58,18 @@ class Kafka extends \Snowflake\Process\Process
|
|||||||
$this->channelListener();
|
$this->channelListener();
|
||||||
|
|
||||||
$kafkaServers = SConfig::get('kafka');
|
$kafkaServers = SConfig::get('kafka');
|
||||||
|
|
||||||
|
$waite = new WaitGroup();
|
||||||
foreach ($kafkaServers as $kafkaServer) {
|
foreach ($kafkaServers as $kafkaServer) {
|
||||||
|
$waite->add();
|
||||||
|
go(function () use ($kafkaServer, $waite) {
|
||||||
|
defer(function () use ($waite) {
|
||||||
|
$waite->done();
|
||||||
|
});
|
||||||
$this->waite($kafkaServer);
|
$this->waite($kafkaServer);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
$waite->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,38 +78,40 @@ class Kafka extends \Snowflake\Process\Process
|
|||||||
*/
|
*/
|
||||||
private function waite(array $kafkaServer)
|
private function waite(array $kafkaServer)
|
||||||
{
|
{
|
||||||
go(function () use ($kafkaServer) {
|
|
||||||
[$config, $topic, $conf] = $this->kafkaConfig($kafkaServer);
|
[$config, $topic, $conf] = $this->kafkaConfig($kafkaServer);
|
||||||
$objRdKafka = new \RdKafka\Consumer($config);
|
$objRdKafka = new \RdKafka\Consumer($config);
|
||||||
$topic = $objRdKafka->newTopic($kafkaServer['topic'], $topic);
|
$topic = $objRdKafka->newTopic($kafkaServer['topic'], $topic);
|
||||||
$topic->consumeStart(0, RD_KAFKA_OFFSET_STORED);
|
$topic->consumeStart(0, RD_KAFKA_OFFSET_STORED);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
$this->resolve($topic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ConsumerTopic $topic
|
||||||
|
*/
|
||||||
|
private function resolve(ConsumerTopic $topic)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$message = $topic->consume(0, $conf['metadataRefreshIntervalMs'] ?? 1000);
|
$message = $topic->consume(0, $conf['interval'] ?? 1000);
|
||||||
if (empty($message)) {
|
if (empty($message)) {
|
||||||
$this->application->debug('message null.');
|
$this->application->debug('message null.');
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
var_dump($message);
|
if ($message->err == RD_KAFKA_RESP_ERR_NO_ERROR) {
|
||||||
switch ($message->err) {
|
|
||||||
case RD_KAFKA_RESP_ERR_NO_ERROR:
|
|
||||||
$this->channel->push([$message->topic_name, $message]);
|
$this->channel->push([$message->topic_name, $message]);
|
||||||
break;
|
} else if ($message->err == RD_KAFKA_RESP_ERR__PARTITION_EOF) {
|
||||||
case RD_KAFKA_RESP_ERR__PARTITION_EOF:
|
|
||||||
$this->application->error('No more messages; will wait for more');
|
$this->application->error('No more messages; will wait for more');
|
||||||
break;
|
} else if ($message->err == RD_KAFKA_RESP_ERR__TIMED_OUT) {
|
||||||
case RD_KAFKA_RESP_ERR__TIMED_OUT:
|
|
||||||
$this->application->error('Kafka Timed out');
|
$this->application->error('Kafka Timed out');
|
||||||
break;
|
} else {
|
||||||
default:
|
$this->application->error($message->errstr());
|
||||||
throw new \Exception($message->errstr(), $message->err);
|
|
||||||
}
|
}
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$this->application->error($exception->getMessage());
|
$this->application->error($exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user