title: Simple embedded Kafka test example with spring boot
body: <p>Edit FYI: <a href="https://github.com/YunaBraska/embedded-kafka-example" rel="noreferrer">working gitHub example</a></p>
  
  <hr>
  
  <p>I was searching the internet and couldn't find a working and simple example of an embedded Kafka test. <br><br>
  My setup is:</p>
  
  <ul>
  <li>Spring boot</li>
  <li>Multiple <a href="https://docs.spring.io/autorepo/docs/spring-kafka-dist/1.1.0.RELEASE/api/org/springframework/kafka/annotation/KafkaListener.html" rel="noreferrer">@KafkaListener</a> with different topics in one class</li>
  <li>Embedded Kafka for test which is starting fine</li>
  <li>Test with Kafkatemplate which is sending to topic but the
  <a href="https://docs.spring.io/autorepo/docs/spring-kafka-dist/1.1.0.RELEASE/api/org/springframework/kafka/annotation/KafkaListener.html" rel="noreferrer">@KafkaListener</a> methods are not receiving anything even after a huge sleep time</li>
  <li>No warnings or errors are shown, only info spam from Kafka in logs</li>
  </ul>
  
  <p>Please help me. There are mostly over configured or overengineered examples. I am sure it can be done simple.
  Thanks, guys!</p>
  
  <pre><code>@Controller
  public class KafkaController {
  
      private static final Logger LOG = getLogger(KafkaController.class);
  
      @KafkaListener(topics = "test.kafka.topic")
      public void receiveDunningHead(final String payload) {
          LOG.debug("Receiving event with payload [{}]", payload);
          //I will do database stuff here which i could check in db for testing
      }
  }
  </code></pre>
  
  <hr>
  
  <p>private static String SENDER_TOPIC = "test.kafka.topic";</p>
  
  <pre><code>@ClassRule
  public static KafkaEmbedded embeddedKafka = new KafkaEmbedded(1, true, SENDER_TOPIC);
  
  @Test
      public void testSend() throws InterruptedException, ExecutionException {
  
          Map&lt;String, Object&gt; senderProps = KafkaTestUtils.producerProps(embeddedKafka);
  
          KafkaProducer&lt;Integer, String&gt; producer = new KafkaProducer&lt;&gt;(senderProps);
          producer.send(new ProducerRecord&lt;&gt;(SENDER_TOPIC, 0, 0, "message00")).get();
          producer.send(new ProducerRecord&lt;&gt;(SENDER_TOPIC, 0, 1, "message01")).get();
          producer.send(new ProducerRecord&lt;&gt;(SENDER_TOPIC, 1, 0, "message10")).get();
          Thread.sleep(10000);
      }
  </code></pre>