Take the IBM Event Streams Java app coding challenge

In the previous tutorial, “Get hands on experience with an IBM Event Streams Java sample application,” we reviewed the logic of the Event Streams Java sample and you played around with changing it up. In this tutorial, you’ll actually build a small application.

In this tutorial, you will first run a small binary application. This application will produce some records to a topic. Then, your challenge is to write a consumer application that will consume records from the topic and that will recover the secret message put inside one of the records.


To complete this challenge, you’ll need the following in your local environment:

The challenge

The challenge is to produce messages by running the producer binary application provided and modify the consumer application to find the secret message.

The producer application will create a topic called event-streams-coding-challenge and send records, one of which is the secret message. The next step will be to edit the example App.java application and add a poll loop in order to keep consuming records until it finds the secret message. The secret message is the value of the record that has the following key: coding-challenge.

Follow these steps to complete the challenge:

  1. Download the challenge code, which is stored in the ibm-messaging/eventstreams-badge-sample GitHub repository.

    Go to our ibm-messaging/eventstreams-badge-sample repository in GitHub, and click the clone or download button. You can choose to Clone with SSH, Use HTTPS, or Download a ZIP with the code. If you download a .ZIP file, unzip the repository.

  2. Run the producer application by providing the broker address and API key found from your Event Streams Service credentials.

     java -jar coding-challenge-setup.jar <kafka_broker_sasl> <api_key>

    Ensure you see “Congratulations! You have successfully set up the topic for the coding challenge.” in the output to confirm the secret message was correctly written to the topic.

    Now it’s time to try to recover the secret message!

  3. Set up a project for the sample consumer application.

    First, navigate to the coding-challenge-consumer directory:

     cd coding-challenge-consumer

    Then, create a project for your preferred IDE: gradle eclipse or gradle idea.

    Finally, import the consumer project into your IDE.

  4. In the IDE, open App.java and modify the code where you see TODO comments.

    There are 4 TODO comments that highlight Consumer logic that is required to complete the challenge.

     // TODO Move position to beginning of partition
     // TODO: Add consumer poll loop
     // TODO: Find the record whose key is equal to KEY ("coding-challenge")
     // TODO: Print the record value to discover the secret message
  5. After you have finished modifying the consumer code, build the application.

     gradle clean && gradle build
  6. Run the consumer application.

     java -jar ./build/libs/coding-challenge-consumer.jar <kafka_broker_sasl> <api_key>

If your code does not work, don’t panic! Just return to step 4, and rerun steps 5 and 6 after you’ve made changes.

If you get stuck, review the explanations of the Event Streams sample in Get hands on experience with Event Streams Java sample as it contains all the logic required to complete the challenge.

Summary and next steps

Congratulations! You’ve successfully written your first Kafka application and completed the coding challenge. Be sure that you’ve checked out the Event Streams cheat sheet, because it’s packed full of ninja moves that every Event Streams user should know.