Skip to content
Magnus Edenhill edited this page Jun 21, 2016 · 13 revisions

Frequently asked questions

Consumer

Are balanced consumer groups supported?

Yes, broker based balanced consumer groups are supported and requires Apache Kafka broker version >= 0.9.

  • C: rd_kafka_subscribe() et.al
  • C++: KafkaConsumer class.

What is a simple consumer?

The Consumer class is the legacy simple consumer that works with any broker >= 0.8, it does not feature any consumer group support but allows full flexibility in regards to partitions to consume and their offsets.

  • C: rd_kafka_consume_start() et.al.
  • C++: Consumer class

What is a high-level balanced consumer?

The KafkaConsumer class is the new high-level balanced consumer which requires broker version >= 0.9, the subscribed topics and partitions are assigned to the memmbers in a consumer group so that only one consumer may consume messages from a single partition at any time.

  • C: rd_kafka_subscribe(), rd_kafka_assign(), et.al.
  • C++: KafkaConsumer class

Why am I not seeing any messages?

If there are no stored offsets for a partition (and group in case of the KafkaConsumer) the consumer will default its starting offset to the topic configuration setting auto.offset.reset which defaults to latest - that is, it will start consuming at the current end of a partition.

If you are using the KafkaConsumer you probably do not have a per-topic configuration object but should use the default topic config, see default_topic_conf.

How do I set topic configuration properties with the KafkaConsumer?

Since you dont need to create any topic objects when using KafkaConsumer you might wonder how to set topic configuration. The default_topic_conf configuration property solves this, it takes a topic configuration object and applies it to all internally created topics as their default configuration.

If you need special configuration for a sub-set of your topics you will need to create them prior to calling subscribe() or assign() and pass their explicit configuration objects at topic creation time.

Producer

Why is there no sync produce() interface?

Because synchronous producing is a performance killer and scales very poorly, it is effectively bound by network and broker latency. If the round-trip to produce a message is 2ms the maximum achievable rate is 500 messages per second. In scenarios where the broker or network is getting slower for whatever reason this rate decreases even more, possibly causing backpressure in the application affecting the upstream data source.

It is thus better to design the application to use asynchronous sends and use the delivery report callback to take action when the message is finally delivered or fails permanently.

If you still think you need a sync producer, see How to implement a sync producer

How do I get the offset of a produced message?

Make sure you use a delivery callback and set the produce.offset.report topic configuration property to true, this comes at a very minimal performance cost.

General

Is librdkafka compatible with my broker version?

Yes, it is. But you need to read this: Broker version compatibility

Is the library thread-safe?

Yes, librdkafka is completely thread-safe (unless otherwise noted in the API documentation). Any API, short of the destructor functions, may be called at any time from any thread. The common restrictions of object destruction still applies (e.g., you must not call rd_kafka_destroy() while another thread is calling rd_kafka_poll() or similar).

Should I use the C or C++ interface?

That is up to you, the library itself is implemented in C and the C++ interface is a thin layer on top of the C code. The C++ interface may lag behind the C interface functionally (but usually not by far).

What version should I use?

For production use: use latest official release (currently 0.9.1)

For testing and development use: use latest master branch

How do I properly terminate my Producer or Consumer without loosing messages?

This is covered in Proper termination sequence

Can librdkafka create, modify or delete topics?

No, there is currently no Kafka protocol support for managing topics, but work is being done in KIP-4.

librdkafka does support automatic topic creation, which needs to be enabled with auto.create.topics.enable=true on the broker.

Clone this wiki locally