PHP code example of kafka-bus / metadata
1. Go to this page and download the library: Download kafka-bus/metadata 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/ */
kafka-bus / metadata example snippets
use KafkaBus\Core\Consumers\ConsumerConfig;
use KafkaBus\Metadata\Metadata;
use KafkaBus\Metadata\Partitions\CommitOffset;
use KafkaBus\Metadata\Partitions\Offset;
$metadata = Metadata::fromConnection($connection);
// All topics and partitions known to the broker
foreach ($metadata->topics()->list() as $topic) {
foreach ($topic->partitions as $partition) {
echo "$topic->name#$partition->id [$partition->offset]\n";
}
}
// Consumer group offsets for your own topics
$partitions = $metadata->partitions(
topics: [$topicRegistry->get('products')],
config: new ConsumerConfig(additionalOptions: ['group.id' => 'products-microservice']),
ownerName: 'products-microservice',
);
foreach ($partitions->list() as $partition) {
echo "{$partition->topic->name}#$partition->id C:$partition->currentOffset MIN:$partition->minOffset MAX:$partition->maxOffset\n";
}
// Rewind partition 0 to the earliest offset (use RD_KAFKA_PARTITION_UA for all partitions)
$partitions->setOffset(new CommitOffset($topicRegistry->get('products'), 0, Offset::Early));