Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Kafka Startup error "Connection to node -1 could not be established. Broker may not be available."

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.

like image 608
Philip Schikora Avatar asked Aug 22 '19 14:08

Philip Schikora


1 Answers

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.

like image 170
Shamil Puthukkot Avatar answered Nov 15 '22 05:11

Shamil Puthukkot