'How to create a topic with multiple partitions using php-librdkafka

I am following this library https://github.com/arnaud-lb/php-rdkafka to write producer codes.

The following code creates a topic "test" with 1 partition and 1 replication factor.

How to create 2 or 3 partitions using this same code logic?

<?php

$conf = new RdKafka\Conf();
$conf->set('metadata.broker.list', 'localhost:9092'); //adding the kafka server address

$producer = new RdKafka\Producer($conf);

$topic = $producer->newTopic("test"); // creating a topic with 1 partition and 1 replication factor

for ($i = 0; $i < 10; $i++) {
    $topic->produce(RD_KAFKA_PARTITION_UA, 0, "Message $i");
    $producer->poll(0);
}

for ($flushRetries = 0; $flushRetries < 10; $flushRetries++) {
    $result = $producer->flush(10000);
    if (RD_KAFKA_RESP_ERR_NO_ERROR === $result) {
        break;
    }
}

?>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source