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
afkaBus\Core\Connections\Config\KafkaConnectionConfig;
use KafkaBus\Core\Connections\Registry\ConnectionRegistry;
use KafkaBus\Metadata\Metadata;
$connections = ConnectionRegistry::default();
$metadata = Metadata::fromConnection($connections->connection('default'));
$topic = $metadata->topics()->get('orders.events');
foreach ($topic->partitions as $partition) {
echo $topic->name . '#' . $partition->id . PHP_EOL;
}
use KafkaBus\Core\Consumers\ConsumerConfig;
use KafkaBus\Core\Topics\Topic;
$orders = new Topic('orders.events', 'orders');
$config = new ConsumerConfig(additionalOptions: ['group.id' => 'orders-service']);
$partitions = $metadata->partitions([$orders], $config);
foreach ($partitions->list() as $partition) {
printf(
"%s#%d: committed=%d, low=%d, high=%d\n",
$partition->topic->name,
$partition->id,
$partition->currentOffset,
$partition->minOffset,
$partition->maxOffset,
);
}
use KafkaBus\Metadata\Partitions\CommitOffset;
use KafkaBus\Metadata\Partitions\Offset;
$results = $partitions->setOffset(new CommitOffset(
topic: $orders,
partition: RD_KAFKA_PARTITION_UA,
offset: Offset::Early,
));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.