title: Spring KafkaListener: How to know when it's ready
body: <p>I have a simple Spring Boot application which reads from Kafka and writes to Kafka. I wrote a <code>SpringBootTest</code> using an <code>EmbeddedKafka</code> to test all that.</p>
  
  <p>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 <code>KafkaListener</code> to be precise) is ready. Since the listener reads from the <code>latest</code> offset (I do not want to change any config for my test - except bootstrap.servers), it will not receive all messages in that test.</p>
  
  <p>Does anyone have an idea how I could know inside the test, that the <code>KafkaListener</code> is ready to receive messages?</p>
  
  <p>Only way I could think of is waiting until <code>/health</code> comes available but I have no idea whether I can be sure that this implies the <code>KafkaListener</code> to be ready at all.</p>
  
  <p>Any help is greatly appreciated!</p>
  
  <p>Best regards.</p>