1

我有一个带有 spring-cloud-starter-bus-kafka 的项目,我在里面设置了 kafka URL,application.yml如下所示:

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 以连接到他们的服务器?

4

2 回答 2

0

你用的是什么版本?使用 2.0,不需要连接到 zookeeper。

对于早期版本,您需要设置spring.cloud.stream.kafka.binder.zkNodes.

Spring Cloud Stream 文档在这里

于 2018-05-15T15:54:41.743 回答
0

Spring的文档中有一段关于它:

https://docs.spring.io/spring-cloud-stream/docs/Ditmars.SR3/reference/htmlsingle/index.html#_kafka_binder_properties

您可以在Application.yml

spring:
  cloud:
    stream:
      kafka:
        binder:
          zkNodes: ADDRESS:PORT
          brokers: ADDRESS:PORT

或使用.properties

spring.cloud.stream.kafka.binder.zkNodes = ADDRESS:PORT
于 2018-11-11T01:16:15.083 回答