Skip to content

Configuration

Matias Fontanini edited this page Apr 29, 2017 · 1 revision

Configuration objects allow easily configuring your consumers/producers. They allow setting parameters on librdkafka's configuration handles while allowing to use types such as integral values, strings and bools as values.

Example:

// Build a configuration to be used on e.g. a consumer/producer
Configuration config = {
    { "metadata.broker.list", "kafka-server:9092" },
    { "enable.auto.commit", false },
    { "queue.buffering.max.ms", 50 }
};

// Build a topic configuration
TopicConfiguration topic_config = {
    { "auto.offset.reset", "smallest" }
};

// Now configure it to be the default topic config
config.set_default_topic_config(topic_config);

Callbacks

Configuration objects support configuring callbacks that will later be used when consuming/producing messages. These all take std::functions as their arguments so you can use any functor that has a valid signature:

Configuration config = ...;
// Set the offset commit callback (maps to rd_kafka_conf_set_offset_commit_cb).
config.set_offset_commit_callback([](Consumer& consumer, Error error,
                                     const TopicPartitionList& topic_partitions) {
    // ....
});
Clone this wiki locally