PHP code example of meitu / php-consumergroup
1. Go to this page and download the library: Download meitu/php-consumergroup library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
meitu / php-consumergroup example snippets
use MTKafka\Consumer;
function call_back_func($msg) {
echo "$msg->payload\n";
}
function handle_error_call_back($msg) {
echo $msg->errstr();
}
$consumer = New Consumer("localhost:2181");
$consumer->setGroupId("group-test");
$consumer->setTopic("topic-test");
$consumer->setOffsetAutoReset(Consumer::SMALLEST);
$consumer->setErrHandler("handle_error_call_back");
try {
$consumer->start("echo_message");
}
catch(Exception $e) {
printf("error: %s\n", $e->getMessage());
}