我有一个带有 spring-cloud-starter-bus-kafka 的项目,我在 application.yml
中设置了 kafka URL,如下所示:
spring.kafka.bootstrap-servers=localhost:9092
当kafka和zookeeper部署在本地时,这可以工作,但是如果我将kafka和zookeeper移动到他们自己的服务器上,我在spring-boot启动时会收到错误:
新配置
spring.kafka.bootstrap-servers=192.168.0.120:9092
错误
{
"@timestamp" : "2018-05-15T14:56:45.628+00:00",
"message" : "Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)",
"logger_name" : "org.apache.zookeeper.ClientCnxn",
"thread_name" : "main-SendThread(localhost:2181)",
"level" : "INFO"
}
{
"@timestamp" : "2018-05-15T14:56:45.629+00:00",
"message" : "Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect",
"logger_name" : "org.apache.zookeeper.ClientCnxn",
"thread_name" : "main-SendThread(localhost:2181)",
"level" : "WARN",
"stack_trace" : "java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)"
}
我应该如何配置kafka和zookeeper连接到他们的服务器?
最佳答案
您使用的是什么版本?在 2.0 中,不需要连接到 Zookeeper。
对于早期版本,您需要设置spring.cloud.stream.kafka.binder.zkNodes
。
关于java - 为 spring-cloud-bus 设置zookeeper主机和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50353869/