title: Configure listener programmatically instead of using annotations
body: <p>I've <a href="https://docs.spring.io/spring-kafka/docs/2.2.8.RELEASE/reference/html/#receiving-messages" rel="nofollow noreferrer">read the documentation about receiving messages</a>:</p>
  
  <blockquote>
    <p>You can receive messages by configuring a MessageListenerContainer and providing a message listener or by using the @KafkaListener annotation.</p>
  </blockquote>
  
  <p>However I can't quite get it to work. I'm using Spring Boot 2.1.2 and have potentially oversalted the Spring Soup with Beans that do more harm than they benefit me, so I'd like to understand how it is supposed to work, so I can check where I strayed from the path of glory.</p>
  
  <p>If I understand the documentation correctly, it could be sufficient to have a <code>MessageListenerContainer</code> configured, e.g. this here:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  public class MyKafkaConfiguration {
    @Bean
    public MessageListenerContainer myVeryOwnListener(ConsumerFactory&lt;String, String&gt; consumerFactory) {
      ContainerProperties cProps = new ContainerProperties(new TopicPartitionInitialOffset("spring-kafka-stackoverflow-questions", /* partition */ 0, /* Offset */ 0L));
      KafkaMessageListenerContainer&lt;String, String&gt; result = new KafkaMessageListenerContainer&lt;&gt;(consumerFactory, cProps);
      result.setupMessageListener(MessageListener&lt;String, String) System.out::println);
      return result;
    }
  }
  </code></pre>
  
  <p>This boots up without exception, but does not seem to actually listen to any messages on the broker.
  From what I get from the usual flow with annotations, there needs to be someone who registers the listener in the form of an <code>KafkaListenerEndpoint</code> to the <code>KafkaListenerEndpointRegistry</code>.</p>
  
  <p>This is automatically done by the <code>KafkaListenerAnnotationBeanPostPorcessor</code> for all methods annotated by <code>@KafkaListener</code> but how is this supposed to work in the case, where I want to take the path </p>
  
  <blockquote>
    <p>by configuring a MessageListenerContainer and providing a message listener </p>
  </blockquote>
  
  <p>instead of </p>
  
  <blockquote>
    <p>using the @KafkaListener annotation</p>
  </blockquote>
  
  <p>I don't quite get it. Also there is no method within the <code>KafkaAutoConfiguration</code> (which Spring Boot provides) which, e.g. takes a <code>List&lt;MessageListenerContainer&gt;</code> and automatically registeres all of them to the registry, so this is not surprising.</p>
  
  <p>But how was it supposed to work in the first place, as the documentation suggests? Did I misunderstand that part?
  Can someone please enlight me?</p>