I have a simple Spring Boot application which reads from Kafka and writes to Kafka. I wrote a SpringBootTest
using an EmbeddedKafka
to test all that.
The main problem is: Sometimes the test fails because the test sends the Kafka message too early. That way, the message is already written to Kafka before the Spring application (or its KafkaListener
to be precise) is ready. Since the listener reads from the latest
offset (I do not want to change any config for my test - except bootstrap.servers), it will not receive all messages in that test.
Does anyone have an idea how I could know inside the test, that the KafkaListener
is ready to receive messages?
Only way I could think of is waiting until /health
comes available but I have no idea whether I can be sure that this implies the KafkaListener
to be ready at all.
Any help is greatly appreciated!
Best regards.