改名
This commit is contained in:
+26
-6
@@ -22,24 +22,44 @@ use function Amp\stop;
|
|||||||
class Kafka extends \Snowflake\Process\Process
|
class Kafka extends \Snowflake\Process\Process
|
||||||
{
|
{
|
||||||
|
|
||||||
protected Channel $channel;
|
/** @var Channel */
|
||||||
|
protected $channel;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConfigException
|
||||||
|
*/
|
||||||
|
// public function initConfig()
|
||||||
|
// {
|
||||||
|
// $kafka = SConfig::get('kafka');
|
||||||
|
// $config = ConsumerConfig::getInstance();
|
||||||
|
// $config->setMetadataRefreshIntervalMs(
|
||||||
|
// $kafka['metadataRefreshIntervalMs'] ?? 1000
|
||||||
|
// );
|
||||||
|
// $config->setMetadataBrokerList($kafka['brokers']);
|
||||||
|
// $config->setGroupId($kafka['groupId']);
|
||||||
|
// $config->setBrokerVersion($kafka['version']);
|
||||||
|
// $config->setTopics($kafka['topics']);
|
||||||
|
// $this->channelListener($kafka);
|
||||||
|
//
|
||||||
|
// return [new Consumer(), $kafka];
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Process $process
|
* @param Process $process
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws \RdKafka\Exception
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function onHandler(Process $process)
|
public function onHandler(Process $process)
|
||||||
{
|
{
|
||||||
$this->channelListener();
|
$this->channelListener();
|
||||||
[$config, $conf] = $this->kafkaConfig();
|
[$config, $conf] = $this->kafkaConfig();
|
||||||
$consumer = new \RdKafka\Consumer($config);
|
$consumer = new KafkaConsumer($config);
|
||||||
$consumer->addBrokers($conf['brokers']);
|
$consumer->subscribe($conf['topics']);
|
||||||
|
|
||||||
$topic = $consumer->newTopic("test");
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$message = $topic->consume(0, 1000);
|
$message = $consumer->consume($conf['metadataRefreshIntervalMs'] ?? 1000);
|
||||||
if (empty($message)) {
|
if (empty($message)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user