Skip to main content

Tuning a Kafka Consumer

Hands-On Lab

 

Photo of Will Boyd

Will Boyd

DevOps Team Lead in Content

Length

00:30:00

Difficulty

Intermediate

You can configure your Kafka consumers in a variety of ways in order to customize their behavior. In many production scenarios, ensuring your consumers perform well for your use case is a matter of tweaking consumer configurations. In this lab, we will work with this process hands-on. We will be provided with some consumer code and a list of issues that can be addressed by changing the consumer configuration. We will then need to identify what configuration changes should be made in order to address these issues, and we will need to implement those changes in the consumer.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Tuning a Kafka Consumer

Introduction

You can configure your Kafka consumers in a variety of ways in order to customize their behavior. In many production scenarios, ensuring your consumers perform well for your use case is a matter of tweaking consumer configurations. In this lab, we will work with this process hands-on. We will be provided with some consumer code and a list of issues that can be addressed by changing the consumer configuration. We will then need to identify what configuration changes should be made in order to address these issues, and we will need to implement those changes in the consumer.

Solution

Log in to the lab server using the credentials provided on the hands-on lab page:

ssh cloud_user@PUBLIC_IP_ADDRESS

Clone the Starter Project from GitHub and Perform a Test Run

  1. Clone the starter project from GitHub (first changing to the home directory if you aren't already in it):

    cd ~/
    git clone https://github.com/linuxacademy/content-ccdak-consumer-tuning-lab.git
  2. Change to the content-ccdak-consumer-tuning-lab directory:

    cd content-ccdak-consumer-tuning-lab
  3. Perform a test run to make sure the code is able to compile:

    ./gradlew run

    The code should compile, but the consumer will fail to run

Implement Configuration Changes to Address the Issues

  1. Edit the Consumer class:

    vi src/main/java/com/linuxacademy/ccdak/consumer/MemberSignupsConsumer.java
  2. In the public MemberSignupsConsumer properties section, increase the minimum fetch size by setting fetch.min.bytes=1024:

    props.setProperty("fetch.min.bytes", "1024");
  3. On the next line, send heartbeats more frequently by setting heartbeat.interval.ms=2000:

    props.setProperty("heartbeat.interval.ms", "2000");
  4. Fix the issue with the offset reset behavior by setting auto.offset.reset=earliest:

    props.setProperty("auto.offset.reset", "earliest");

    Save and exit the file.

  5. Run your code to verify it still works:

    ./gradlew run

Conclusion

Congratulations on successfully completing this hands-on lab!