RdKafka\KafkaConsumer::subscribe

(PECL rdkafka >= 1.0.0, librdkafka >= 0.9)

RdKafka\KafkaConsumer::subscribeUpdate the subscription set

Description

public RdKafka\KafkaConsumer::subscribe ( array $topics ) : void

Update the subscription set to topics.

This overrides the current assignment. Any previous subscription will be unassigned and unsubscribed first.

The subscription set denotes the desired topics to consume. This set is provided to the partition assignor (one of the elected group members) for all clients which then uses the configured partition.assignment.strategy to assign the subscription sets's topics's partitions to the consumers, depending on their subscription.

The result of such an assignment is a rebalancing which is either handled automatically in librdkafka or can be overriden by the application by providing a rebalance_cb.

The rebalancing updates what partitions are actually being fetched by the RdKafka\KafkaConsumer.

Regex pattern matching automatically performed for topics prefixed with ^ (e.g. ^myPfx[0-9]_.*)

Note:

The default configuration for subscribed topics can be changed by calling RdKafka\Conf::set().

Parameters

topics (array)

Array of topic names.

Regex pattern matching automatically performed for topics prefixed with ^ (e.g. ^myPfx[0-9]_.*)

Errors/Exceptions

Examples

Example #1 RdKafka\KafkaConsumer::subscribe() example

<?php
$kafkaConsumer
->subscribe([
    
"logs",
    
"^myPfx[0-9]_.*",
]);
?>

See Also