An integration test to validate that a kafka message was published by read side processor using alpakka
A POC to start a Kafka Container, a PostrgeSQL Container and a Lagom Application to persist en event in the event journal, publish a kafka message in a topic and consume it in an Integration Test
- scala 2.13.8
- Lagom 1.6.7
- Alpakka 3.0.0
- ScalaTest 3.3.3
- Test Containers 0.40.3
The entry point of the application. Once we start the service it will execute this class to instantiate all the
required components such as the KafkaProducer
that publish messages in a kafka topic and also registers the read
side processor.
It contains the logic to start a Producer and publish a kafka message in a topic.
Each time an event is persisted, it will use the KafkaHelper
to publish the message in Kafka.
PocHelloMessagePublisherTest - It starts a Kafka and PostgreSQL containers, then starts the Lagom Application using the PocServiceLoader as a Loader class where it instantiates all the required components such as the KafkaHelper and register PocHelloMessagePublisher as a read side processor. With the ReadSideTestDriver it simulates that an event was persisted in the event journal. Doing that the read side processor will pick up that event and publish a message in a kafka topic. Then a Consumer will subscribe to the same topic to be able to consume that message. The test can be executed using the following command
sbt test
In the log messages you would be able to see the kafka and postgresql containers starting, then the service application, followed by the kafka producer and finally the test starting the consumer to validate that the message was published in the topic as expected