Search code examples
spring-bootapache-kafkaspring-kafka

spring boot KafkaListener with mulitple group ids


    @KafkaListener(topics = "test, groupId = "G1")
  public void receiveMessage(@Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String key,
      @Payload final String message) {
    doStuff();
  }

I have 6 partitions and want to create 6 consumer in same group, lets say in one machine. how can I achieve it ? 1.by deploying 6 instances of app 2.by creating 6 consumers in same app (duplicate code) any alternatives/suggestion ?


Solution

  • If you are talking about the same consumer group, there is just enough to configure a ConcurrentKafkaListenerContainerFactory for an appropriate concurrency configuration property:

    spring.kafka.listener.concurrency = 6
    

    See Spring Kafka Reference Manual for more information what and how that concurrency option means.