2 u012575301 u012575301 于 2017.08.29 17:38 提问

有人使用过 nmred/kafka吗 有关nmred/kafka的问题

consumer.php

$logger = new Logger('my_logger');
// Now add some handlers
// $logger->pushHandler(new StdoutHandler());
$config = \Kafka\ConsumerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('127.0.0.1:9092');
$config->setGroupId('test');
$config->setBrokerVersion('0.10.2.1');
$config->setTopics(array('test'));
$config->setOffsetReset('earliest');
$consumer = new \Kafka\Consumer();
$consumer->setLogger($logger);
$consumer->start(function($topic, $part, $message) {
var_dump($message);
});
producer.php

$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('127.0.0.1:9092');
$config->setBrokerVersion('0.10.0.1');
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer(function() {
return array(
array(
'topic' => 'test',
'value' => 'dgjll90',
'key' => '',
),
);
});
$producer->setLogger($logger);
$producer->success(function($result) {
var_dump($result);
});
$producer->error(function($errorCode) {
var_dump($errorCode);
});
$producer->send(true);
生产者是没有问题的,能正常发送
但是消费者(consumer)始终得不到数据,查看日志,发现,到最后一直循环
my_logger.DEBUG: Start Request ClientId: kafka-php ApiKey: HeartbeatRequest ApiVersion: 0 [] []
这句话

但有的时候又能正常返回数据,但一般几率很小,差不多10几次一次能正常返回,其他时候就是一直循环上面那句话

求解答

Csdn user default icon
上传中...
上传图片
插入图片