在配置kafka服务器后,使用libkafka去连接远程(i.e. not localhost)的broker,总是失败,报错如下
rdkafka_example -P -b 192.168.150.229:9092,192.168.150.229:9093 -t test
% Created producer rdkafka#producer-1
LOG-3-FAIL: 192.168.150.229:9092/bootstrap: Connect to ipv4#192.168.150.229:9092
failed: 由于目标计算机积极拒绝,无法连接。
你的config/server.properties需要明确写出listeners的ip地址,而不能用localhost或者127.0.0.1代替
listeners=PLAINTEXT://192.168.150.229:9092
# The port the socket server listens on
#port=9092
# Hostname the broker will bind to. If not set, the server will bind to all interfaces
#host.name=localhost
你要么设置listteners要么设置port、host.name,二选一。
如果你只是本机使用,没有准备让其他机器的客户端连接过来,你可以用localhost或者127.0.0.1代替
如果你在搭建集群,一定要设置listteners或host.name为明确的ip