chapter five

5 Consumers: unlocking data

 

This chapter covers:

  • Exploring the consumer read path and how it works
  • Learning about offsets and their use
  • Examining various configuration options for consumer clients

In our previous chapter, we started working with writing data into our Kafka system. However, as you know, that is only one part of the story. Consumers are the way that we get data from Kafka and to other systems or applications that use that data to provide value. Since consumers are clients that can exist outside of brokers, they have the same language options available as we do the producer clients. Please take note that when we are looking at how things work below, I will try to lean towards the defaults of the Java consumer client.

After reading this chapter, we will be on our way to solving our previous business requirements by consuming data in a couple of different ways.

5.1  Introducing the Consumer

The consumer client is the program that subscribes to the topic or topics that it is interested in. As with producers, the actual consumer processes can run on separate machines. Consumers are not required to run on a specific server, as long as they can connect to the message brokers, they are good to read messages.

Figure 5.1. Kafka Consumers
Consumers in Context

5.2  Important Configuration

5.2.1  Understanding Tracking Offsets

5.3  Consumer Groups

5.4  The Need for Offsets

5.4.1  GroupCoordinator

5.4.2  ConsumerRebalanceListener

5.4.3  Partition Assignment Strategy

5.4.4  Standalone Consumer

5.4.5  Manual Partition Assignment

5.5  Auto or Manual Commit of Offsets

5.6  Reading From a Compacted Topic

5.7  Reading for a Specific Offset

5.7.1  Start at the beginning

5.7.2  Going to the end

5.7.3  Seek to an Offset

5.7.4  Offsets For Times

5.8  Reading Concerns

5.8.1  Broker use of Consumers