Skip to content

Commit

Permalink
Update doc and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Nov 24, 2020
1 parent ab74400 commit 97b1433
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
8 changes: 6 additions & 2 deletions doc/consumer.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function consume(ConsumeMessage $message)
}
$config = new ConsumerConfig();
$config->setBroker('127.0.0.1:9092');
$config->setTopic('test');
$config->setTopic('test'); // 主题名称
$config->setGroupId('testGroup'); // 分组ID
$config->setClientId('test'); // 客户端ID
$config->setInterval(0.1);
$consumer = new Consumer($config, 'consume');
$consumer->start();
Expand All @@ -66,7 +68,9 @@ use longlang\phpkafka\Consumer\ConsumerConfig;

$config = new ConsumerConfig();
$config->setBroker('127.0.0.1:9092');
$config->setTopic('test');
$config->setTopic('test'); // 主题名称
$config->setGroupId('testGroup'); // 分组ID
$config->setClientId('test'); // 客户端ID
$consumer = new Consumer($config);
while(true) {
$message = $consumer->consume();
Expand Down
6 changes: 3 additions & 3 deletions examples/consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function consume(ConsumeMessage $message)
}
$config = new ConsumerConfig();
$config->setBroker('127.0.0.1:9092');
$config->setTopic('test');
$config->setGroupId('testGroup');
$config->setClientId('test');
$config->setTopic('test'); // 主题名称
$config->setGroupId('testGroup'); // 分组ID
$config->setClientId('test'); // 客户端ID
$config->setInterval(0.1);
$consumer = new Consumer($config, 'consume');
$consumer->start();
Expand Down
9 changes: 5 additions & 4 deletions examples/consumer_custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

$config = new ConsumerConfig();
$config->setBroker('127.0.0.1:9092');
$config->setTopic('test');
$config->setGroupId('testGroup');
$config->setClientId('test');
$config->setTopic('test'); // 主题名称
$config->setGroupId('testGroup'); // 分组ID
$config->setClientId('test'); // 客户端ID
$consumer = new Consumer($config);
while (true) {
$message = $consumer->consume();
if ($message) {
var_dump($message->getKey() . ':' . $message->getValue());
$consumer->ack($message->getPartition()); // ack
} else {
usleep(10000);
}
sleep(1);
}

return;
2 changes: 1 addition & 1 deletion examples/producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
while (true) {
$producer->send('test', (string) microtime(true), uniqid('', true));
var_dump(++$i);
sleep(3);
sleep(1);
}

return;

0 comments on commit 97b1433

Please sign in to comment.