1

I have a project with spring-cloud-starter-bus-kafka and I set the kafka URL inside application.yml like so:

spring.kafka.bootstrap-servers=localhost:9092

This works find when kafka and zookeeper are deployed locally, but if I move kafka and zookeeper to their own servers I get an error when spring-boot starts:

New config

spring.kafka.bootstrap-servers=192.168.0.120:9092

Error

{
    "@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)"
}

How I should config kafka and zookeeper to connect to their servers?

madmaux
  • 51
  • 8

2 Answers2

0

What version are you using? With 2.0, no connection to zookeeper is required.

With earlier versions, you need to set spring.cloud.stream.kafka.binder.zkNodes.

Spring Cloud Stream documentation here.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I'm using `1.5.10.RELEASE` and also tried `spring.cloud.stream.kafka.binder.zkNodes=192.168.0.120:9092` but didn't work – madmaux May 15 '18 at 15:56
  • No; you need port 2181 (by default) for ZK - 9092 is the kafka broker. – Gary Russell May 15 '18 at 15:58
  • Didn't work either, still trying to connect to localhost: { "@timestamp" : "2018-05-15T16:09:07.898+00:00", "message" : "Initiating client connection, connectString=localhost:2181 sessionTimeout=10000 watcher=org.I0Itec.zkclient.ZkClient@653b9612", "logger_name" : "org.apache.zookeeper.ZooKeeper", "thread_name" : "main", "level" : "INFO" } – madmaux May 15 '18 at 16:38
  • I just tested it by adding a bogus zkNodes value - pointing to a server that doesn't have ZK running, and got your error; you must have configured it incorrectly. – Gary Russell May 15 '18 at 16:42
  • Not sure what else I'm doing wrong if I telnet 192.168.0.120:2181 I get connected, this is what i have in my application.yml file: `spring.cloud.bus.trace.enabled=true` `spring.cloud.bus.ack.enabled=false` `spring.cloud.bus.refresh.enabled=false` `spring.cloud.stream.kafka.zkNodes=192.168.0.120` `spring.kafka.bootstrap-servers=192.168.0.120:9092` – madmaux May 15 '18 at 17:22
  • I've also tried with and without this `spring.kafka.bootstrap-servers=192.168.0.120:9092` while have the zkNodes configured and didn't work. – madmaux May 15 '18 at 17:23
  • `spring.cloud.stream.kafka..zkNodes=192.168.0.120` should be `spring.cloud.stream.kafka.binder.zkNodes`. – Gary Russell May 15 '18 at 17:24
  • yes, sorry about that was a typo when I've pasted the config here, but yeah, that is what I have: `spring.cloud.stream.kafka.binder.zkNodes` – madmaux May 15 '18 at 17:30
  • Well, I just copied yours and added `binder` `spring.cloud.stream.kafka.binder.zkNodes=192.168.0.120` and I get `Opening socket connection to server 192.168.0.120/192.168.0.120:2181. Will not attempt to authenticate using SASL (unknown error)`, followed by `Client session timed out, have not heard from server in 10006ms for sessionid 0x0`. So there's something else you are doing incorrectly - are you sure that properties file is the one being used? – Gary Russell May 15 '18 at 17:34
  • Thank you @Gary Russell, I'm using a config-server and it was down, so I restarted and now the app it's taking the proper config – madmaux May 15 '18 at 17:49
0

There's a section on Spring's documentation about it:

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

You can replace the default URL on Application.yml

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

Or using .properties

spring.cloud.stream.kafka.binder.zkNodes = ADDRESS:PORT
Felipe Passos
  • 17
  • 1
  • 5