Kafka 0.8.2
Consumer API
API usage
Kafka tutorial
API Guide

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.

Practice system design

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:

  1. create Properties
  2. build a ConsumerConfig
  3. create a ConsumerConnector
  4. request message streams for a topic
  5. iterate over the messages

Minimal Java Consumer Example

java
1import java.util.HashMap;
2import java.util.List;
3import java.util.Map;
4import java.util.Properties;
5
6import kafka.consumer.Consumer;
7import kafka.consumer.ConsumerConfig;
8import kafka.consumer.ConsumerIterator;
9import kafka.consumer.KafkaStream;
10import kafka.javaapi.consumer.ConsumerConnector;
11
12public class Kafka082Consumer {
13
14    public static void main(String[] args) {
15        Properties props = new Properties();
16        props.put("zookeeper.connect", "localhost:2181");
17        props.put("group.id", "demo-group");
18        props.put("zookeeper.session.timeout.ms", "400");
19        props.put("zookeeper.sync.time.ms", "200");
20        props.put("auto.commit.interval.ms", "1000");
21
22        ConsumerConfig config = new ConsumerConfig(props);
23        ConsumerConnector consumer = Consumer.createJavaConsumerConnector(config);
24
25        Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
26        topicCountMap.put("orders", 1);
27
28        Map<String, List<KafkaStream<byte[], byte[]>>> streams =
29            consumer.createMessageStreams(topicCountMap);
30
31        List<KafkaStream<byte[], byte[]>> orderStreams = streams.get("orders");
32
33        try {
34            for (KafkaStream<byte[], byte[]> stream : orderStreams) {
35                ConsumerIterator<byte[], byte[]> it = stream.iterator();
36
37                while (it.hasNext()) {
38                    byte[] message = it.next().message();
39                    System.out.println(new String(message, "UTF-8"));
40                }
41            }
42        } catch (Exception e) {
43            e.printStackTrace();
44        } finally {
45            consumer.shutdown();
46        }
47    }
48}

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:

java
topicCountMap.put("orders", 1);

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.connect points at ZooKeeper'
  • 'group.id determines which consumer group this process joins'
  • 'auto.commit.interval.ms controls how often offsets are committed automatically'
  • 'zookeeper.session.timeout.ms affects 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:

java
consumer.shutdown();

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 KafkaConsumer API.
  • The usual flow is ConsumerConfig to ConsumerConnector to KafkaStream.
  • 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.