11

I am trying to start Spring-Kafka with Spring Boot 2.1.7.RELEASE on localhost with Java 12.

Getting the Error: "org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-1, groupId=inter] Connection to node -1 could not be established. Broker may not be available."

I tried switching the Java Version to 11 and 8 and various Properties

spring:
  kafka:
    consumer:
      #bootstrap-servers: localhost:9092
      group-id: inter
      auto-offset-reset: earliest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
    producer:
      bootstrap-servers: localhost:9092
@Service
public class KafkaHalloWorldMessagingService {

    private KafkaTemplate<String, String> kafkaTemplate;

    @Autowired
    public KafkaHalloWorldMessagingService(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    public void sendHalloToTheSystem(String messageToSend) {
        kafkaTemplate.send("interlinked.hallo.topic", messageToSend);
    }
}

@Component
public class KafkaHalloWorldListener {

    @KafkaListener(topics = "interlinked.hallo.topics", groupId = "inter")
    public void handle(String messageToListenTo) {
        System.out.println(messageToListenTo.toUpperCase());
    }
}

2019-08-22 16:25:20.580 WARN 5865 --- [ restartedMain] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-1, groupId=inter] Connection to node -1 could not be established. Broker may not be available.

Philip Schikora
  • 283
  • 1
  • 3
  • 9

1 Answers1

4

Make sure the bootstrap server value in the yml file and the listener in the Kafka server.properties file is same.

Update these two values in the server.properties file. It can be seen in the config folder of Kafka download directory.

zookeeper.connect=Your IpV4 addrees:2181

listeners=PLAINTEXT://Your IpV4 addrees:9092

eg:zookeeper.connect=10.147.2.161:2181

And why is the consumer's boot strap server property commented out?

Please use the producer's boot strap server value for consumer too.

spring.kafka.bootstrap-servers = Your IpV4 addrees:9092

Or split

producer:
     bootstrap-servers: =Your IpV4 addrees:9092
consumer:
     bootstrap-servers: =Your IpV4 addrees:9092:

Hope your zookeeper and kafka is up.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Shamil Puthukkot
  • 442
  • 2
  • 17
  • Thank you very much! I will try it – Philip Schikora Aug 23 '19 at 13:05
  • I havent gotten around to it yet. I think i have to read more on the subject, because i have no idea what zookeeper does and i was under the impression, that spring boot handles most of the things i need to start. Thank you so much for your time by the way! – Philip Schikora Aug 27 '19 at 06:29
  • Briefly zookeeper is Kafka's cluster manager. If you need to delete a topic for example, you can use zookeper instance to delete the topic from all kafka servers: ./kafka-topics.sh --zookeeper localhost: 2181 --delete --topic "topic name". – Aldo Inácio da Silva Feb 05 '21 at 16:47
  • How it is work in Docker? – Margi212 Apr 20 '23 at 14:26