[Kafka Cookbook] Simple Consumer

In the last post we saw Simple Producer, now let's take a look at a Simple Consumer. Please refer Simple Producer for Pre-conditions.

Jumping to next step, lets quickly look at the code.

Let's look at the configuration options. We won't dig deeper into them as of now

Here we have to provide additional information like
zookeeper.connect (Zookeeper info)
group.id - User specified Consumer group name, we just choose default as name
partition.assignment.strategy - How the partition assignment shall work

With the above configuration options, we create a ConsumerConfig. Before we can do anything, we need to create the message stream. Let's see the logical flow

  • Create a ConsumerConnector
  • Create a message stream by passing map of topics of interest
  • The step above returns list of KafkaStreams for a topic
  • Using the list process the KafkaStream for incoming messages
  • In our example we just print the messages

This it it for now. The Consumer needs a deeper look, which we shall cover in subsequent sections.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.