Spring Boot Kafka 启动错误“无法建立与节点 -1 的连接.经纪人可能不可用." [英] Spring Boot Kafka Startup error "Connection to node -1 could not be established. Broker may not be available."
问题描述
我正在尝试使用 Java 12 在本地主机上使用 Spring Boot 2.1.7.RELEASE 启动 Spring-Kafka.
I am trying to start Spring-Kafka with Spring Boot 2.1.7.RELEASE on localhost with Java 12.
出现错误:org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-1, groupId=inter] 无法建立到节点 -1 的连接.代理可能不可用."
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."
我尝试将 Java 版本切换到 11 和 8 以及各种属性
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] 无法连接到节点 -1成立.经纪人可能不可用.
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.
推荐答案
确保 yml 文件中的 bootstrap server 值和 Kafka server.properties 文件中的 listener 值相同.
Make sure the bootstrap server value in the yml file and the listener in the Kafka server.properties file is same.
更新 server.properties 文件中的这两个值.在Kafka下载目录的config文件夹中可以看到.
Update these two values in the server.properties file. It can be seen in the config folder of Kafka download directory.
zookeeper.connect=您的 IpV4 地址:2181
listeners=PLAINTEXT://您的 IpV4 地址:9092
例如:zookeeper.connect=10.147.2.161:2181
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
或者拆分
producer:
bootstrap-servers: =Your IpV4 addrees:9092
consumer:
bootstrap-servers: =Your IpV4 addrees:9092:
希望你的动物园管理员和 kafka 成功.
Hope your zookeeper and kafka is up.
这篇关于Spring Boot Kafka 启动错误“无法建立与节点 -1 的连接.经纪人可能不可用."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!