0

This is a follow up question on my previous post. I am fairly new on both Kafka and Docker and I appreciate any detailed explanation.

I successfully setup my Kafka cluster using docker with zookeeper and kafdrop. Now, I want to connect my Spring project to connect to this cluster using Spring Kafka.

At first it successfully connected and I saw topics were automatically created. But then, I encountered this error that kept on running:

11:27:27.727 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Group coordinator 66aa896dd4c0:9092 (id: 2147482646 rack: null) is unavailable or invalid, will attempt rediscovery
11:27:27.730 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Discovered group coordinator 66aa896dd4c0:9092 (id: 2147482646 rack: null)
11:27:27.730 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=c*****] Discovered group coordinator 6043a3559f58:9092 (id: 2147482644 rack: null)
11:27:27.730 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Discovered group coordinator 6043a3559f58:9092 (id: 2147482644 rack: null)
11:27:27.730 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Group coordinator 66aa896dd4c0:9092 (id: 2147482646 rack: null) is unavailable or invalid, will attempt rediscovery
11:27:27.730 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Group coordinator 6043a3559f58:9092 (id: 2147482644 rack: null) is unavailable or invalid, will attempt rediscovery
11:27:27.730 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Group coordinator 6043a3559f58:9092 (id: 2147482644 rack: null) is unavailable or invalid, will attempt rediscovery
11:27:27.732 INFO  o.a.k.c.c.i.AbstractCoordinator         - [Consumer clientId=*****, groupId=*****] Discovered group coordinator 66aa896dd4c0:9092 (id: 2147482646 rack: null)

Based on this log, the group coordinator keeps being discovered and lost.

This is my Consumer Config

 @Bean
    public Map<String, Object> consumerConfigs() {

        Map<String, Object> props = new HashMap<>();
        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092,localhost:9093,localhost:9094");
        props.put(ConsumerConfig.GROUP_ID_CONFIG, 1);
        props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true);
        props.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "1500");
        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);

        return props;
    }

Producer Config

 @Bean
    public Map<String, Object> producerConfigs() {

        Map<String, Object> props = new HashMap<>();
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092,localhost:9093,localhost:9094");
        props.put(ProducerConfig.RETRIES_CONFIG, 0);
        props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16384);
        props.put(ProducerConfig.LINGER_MS_CONFIG, 1);
        props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);

        return props;
    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
NothingBox
  • 345
  • 5
  • 15
  • can you **ping 66aa896dd4c0** or **ping 6043a3559f58** successfully?, if not, bind the ip in your **/etc/hosts** – clevertension Aug 27 '20 at 06:22
  • I have already added them and can connect successfully. i had a different error when it is not added – NothingBox Aug 27 '20 at 07:39
  • in host 66aa896dd4c0, can kafka ping 6043a3559f58 successfully? or vice versa – clevertension Aug 27 '20 at 08:01
  • Do you mean inside the docker container? – NothingBox Aug 27 '20 at 14:26
  • If your Java code is running in a container, then `localhost` would be the container itself. Otherwise, the error seems to indicate that the advertised brokers are using their Docker service IDs rather than any names that you have assigned to them. Try using `kafkacat -L` command to see what listeners are configured for the cluster (and note: multiple brokers on one machine will be slower than just one) – OneCricketeer Aug 27 '20 at 19:37
  • whenver in docker or other environment, kafka brokers should ping successful mutually, and the consumer should ping all brokers successfully – clevertension Aug 28 '20 at 01:20
  • If I understand correctly, I need to go inside on one kafka docker container and ping the other container via service ID. However, ping command is not available on bitnami/kafka. @OneCricketeer, thanks for the tip. I am just doing mock setup for em to understand how docker and kafka works. :) – NothingBox Aug 28 '20 at 06:18
  • `ping` does not appropriately check ports or advertised listeners, though. – OneCricketeer Aug 28 '20 at 17:58
  • I tested docker compose with only one kafka broker and it is working. So it means that it is my brokers not being able to connect to each other. Any idea how to solve this issue? Thanks – NothingBox Sep 03 '20 at 04:53

0 Answers0