How to use Consumer API of Kafka 0.8.2?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Kafka 0.8.2 uses the older high-level consumer API, which is very different from the modern KafkaConsumer API found in later Kafka versions. If you are working with 0.8.2 specifically, the usual pattern is to configure ZooKeeper-backed consumer settings, create a ConsumerConnector, and read messages from KafkaStream objects.
The Old Consumer Model in 0.8.2
In Kafka 0.8.2, consumers typically coordinate through ZooKeeper. Offsets, group membership, and partition assignments follow that older design, so examples from newer Kafka documentation will not map directly.
The basic flow is:
- create
Properties - build a
ConsumerConfig - create a
ConsumerConnector - request message streams for a topic
- iterate over the messages
Minimal Java Consumer Example
That example creates one consumer thread for the topic and prints each message as text.
How Topic Streams Work
The topicCountMap tells Kafka how many consumption streams you want per topic. In the example above:
That means one stream for the orders topic in this consumer process. If you request more streams, you normally also create matching worker threads to process them in parallel.
Parallelism only helps up to the number of partitions available. Asking for more streams than partitions does not create more real concurrency for that topic.
Important Configuration Keys
A few properties matter more than the others:
- '
zookeeper.connectpoints at ZooKeeper' - '
group.iddetermines which consumer group this process joins' - '
auto.commit.interval.mscontrols how often offsets are committed automatically' - '
zookeeper.session.timeout.msaffects group coordination timing'
Because this is the old API, you should expect ZooKeeper to be part of the setup. That alone distinguishes it from later Kafka client examples.
Threading and Shutdown
Kafka 0.8.2 consumers often create one worker per stream. Even in simple demos, remember to shut the connector down cleanly:
Without proper shutdown, the process can leave resources open or rebalance less cleanly.
If you evolve the sample into a multi-threaded consumer, make sure message handling and shutdown coordination are explicit. The high-level API is older and less ergonomic than the modern client libraries.
Common Pitfalls
The biggest mistake is using modern Kafka consumer examples for Kafka 0.8.2. The APIs, configuration style, and coordination model are different.
Another common issue is forgetting ZooKeeper. In this generation of the API, the consumer setup depends on it.
Developers also sometimes ask for multiple streams but never create worker threads to process them, which defeats the point of parallel consumption.
Finally, do not forget to close the consumer connector. A small example can get away with a rough exit, but real applications should shut down cleanly and deliberately.
Summary
- Kafka 0.8.2 uses the older high-level consumer API, not the modern
KafkaConsumerAPI. - The usual flow is
ConsumerConfigtoConsumerConnectortoKafkaStream. - Consumer coordination in this version depends on ZooKeeper.
- Requested stream count should match the actual concurrency you plan to run.
- Clean shutdown matters, especially once the sample grows into a real service.
Related reading
- How to use Flink's KafkaSource in Scala?
- How to use from_json with Kafka connect 0.10 and Spark Structured Streaming?
- How to use kafka-node under typescript?
- how to use Kafka 0.8 Log4j appender
- How to use Dataset API to read TFRecords file of lists of variant length?
- How to use Firebase with Spring boot REST Application?
- how to use kafka acls?
- How to use kafka and storm on cloudfoundry?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.