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?
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
Or using
.properties