title: Spring kafka Consume multiple Message types in one consumer
body: <p>I have multiple producers that can send multiple type of event to one kafka topic.</p>
  
  <p>And I have a consumer that must consume all type of message. with different logic for every type of message.</p>
  
  <pre><code>    @KafkaListener(topics = "test", containerFactory = "kafkaListenerContainerFactory")
  public void handleEvent(Message&lt;EventOne&gt; event) {
      logger.info("event={}", event);
  }
  </code></pre>
  
  <p>But in this case all messages come to this method not only EventOne</p>
  
  <p>If I implement two method (for every type of message) then all messages come to only one method.</p>
  
  <p>If i implement listener like this:</p>
  
  <pre><code>    @KafkaListener(topics = "test", containerFactory = "kafkaListenerContainerFactory")
  public void handleEvent(Message&lt;?&gt; event) {
      logger.info("event={}", event);
  }
  </code></pre>
  
  <p>then I get exception:
  org.springframework.kafka.KafkaListenerEndpointContainer#0-0-kafka-listener-1] ERROR org.springframework.kafka.listener.LoggingErrorHandler - Error while processing: ConsumerRecord java.lang.IllegalArgumentException: Unrecognized Type: [null]</p>
  
  <p>Please tell how I can implement multiple type consumer?</p>