Charnjeet Singh
Charnjeet Singh

Reputation: 3107

How to read same kafka message at multiple Consumer

I am very new to Kakfa Spring integration. I have implemented the Kafka message sending and One Listener and it working fine for me. But I want to Listener same message at two place. Can any one help me. Below is my code.

 spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.auto-commit-interval=100
spring.kafka.consumer.bootstrap-servers=localhost:9092
spring.kafka.consumer.enable-auto-commit=true
spring.kafka.consumer.group-id=sample-group


spring.kafka.producer.batch-size= 16384
spring.kafka.producer.bootstrap-servers=localhost:9092
spring.kafka.producer.retries= 0
spring.kafka.producer.buffer-memory=33554432

spring.kafka.template.default-topic=spring-topic

Sender Code:

public void testSimple() {
        System.out.println("Sending Topic Here");
        template.send("spring-topic", 0, "foo");
        template.flush();
    }

Receiver:

@KafkaListener(id = "foo", topics = "spring-topic")
    public void listen1(String foo) {
        System.out.println("Got Notification Here");
        this.latch1.countDown();
    }

Can any help me how to read same message at different place.

Upvotes: 1

Views: 1577

Answers (1)

Sönke Liebau
Sönke Liebau

Reputation: 1973

If you change the consumer group in this line:

spring.kafka.consumer.group-id=sample-group

to something else in the second consumer it will get all messages as well.

This article explains a bit more about consumer groups and is worth a read.

Upvotes: 7

Related Questions