Member-only story
Integration Tests for Kafka Consumer
Using embeddedKafka
and JUnit5
Introduction
Recently, I wrote a comprehensive tutorial on how to build an event-driven application with Kafka and DynamoDB. The tutorial covers the end-to-end of building a working application which exposes 2 x endpoints:
- 1 x
POST
endpoint to receive a request to create a new user - 1 x
GET
endpoint to return a user information
The POST
endpoint publishes a message containing a user creation request from the client to a Kafka topic. There’s a Kafka listener pipeline that subscribes to this topic, consumes the messages, and, finally, persists the new user information in a DynamoDB table. Check out the tutorial for more information.
In this tutorial, we will be looking at how to write an integration test for our POST
route, particularly on the Kafka Producer component. We will be using embeddedKafka
and JUnit5
.
TLDR — Github repo here.
Please note the dependencies in build.gradle.kts
and the Gradle wrapper version have been upgraded as per this pull request.
Prerequisites
To be able to follow along, please clone this Github repo to your local machine. Though not compulsory, it is highly…