title: How to implement a stateful message listener using Spring Kafka?
body: <p>I'd like to implement a stateful listener using the Spring Kafka API.</p>
  
  <p>Given the following:</p>
  
  <ul>
  <li>A ConcurrentKafkaListenerContainerFactory, with concurrency set to "n"</li>
  <li>A @KafkaListener annotated method, on a Spring @Service class</li>
  </ul>
  
  <p>Then "n" KafkaMessageListenerContainers will be created. Each one of these will have its own KafkaConsumer, and hence there will be "n" consumer threads - one per consumer.</p>
  
  <p>When messages are consumed, the @KafkaListener method will be called using the same thread that polled the underlying KafkaConsumer. Since there is only on instance of the listener, this listener needs to be thread safe since there will be concurrent access from "n" threads.</p>
  
  <p>I'd like not to think about concurrent access, and hold state in a listener which I know will only ever be accessed by one thread.</p>
  
  <p>How can you create a separate listener per Kafka consumer using the Spring Kafka API?</p>