无法写卡夫卡,经纪人已倒闭

时间:2020-05-28 14:42:53

标签: apache-kafka kafkacat

我在本地运行Kafka。当我尝试写给Kafka时,出现以下错误:

useEffect

我让Kafka在9092端口上监听:

kafkacat -b localhost:9092 -t req -T -P -l  msgs
hello
world
% ERROR: Local: Broker transport failure: localhost:9092/bootstrap: Connect to ipv6#[::1]:9092 failed: Connection refused (after 1ms in state CONNECT)
% ERROR: Local: All broker connections are down: 1/1 brokers are down : terminating

这是kafka配置的相关部分:

bash-3.2$ netstat -an | grep 9092
tcp4       0      0  127.0.0.1.9092         127.0.0.1.50994        ESTABLISHED
tcp4       0      0  127.0.0.1.50994        127.0.0.1.9092         ESTABLISHED
tcp4       0      0  127.0.0.1.9092         127.0.0.1.50986        ESTABLISHED
tcp4       0      0  127.0.0.1.50986        127.0.0.1.9092         ESTABLISHED
tcp4       0      0  127.0.0.1.9092         127.0.0.1.50984        ESTABLISHED
tcp4       0      0  127.0.0.1.50984        127.0.0.1.9092         ESTABLISHED
tcp4       0      0  127.0.0.1.9092         *.*                    LISTEN
bash-3.2$
bash-3.2$ telnet 127.0.0.1 9092
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

我做错了什么?为什么我不能在本地Kafka中写一些条目?

P.S。

当我使用Kafka随附的脚本时,我可以创建主题:

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://127.0.0.1:9092
bootstrap.servers=127.0.0.1:9092

但是当我使用kafkacat /usr/local/bin/kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic Hoffman02 Created topic Hoffman02. 时,它会永远挂起,但仍然可以在日志文件夹kafkacat -b localhost:9092 -t Hoffman04 -P中找到文件Hoffman04:

ls -lrt /usr/local/var/lib/kafka-logs

1 个答案:

答案 0 :(得分:0)

取决于您的OS(尤其是OSX),localhost可能同时解析到ipv4和ipv6地址,而您的代理仅绑定到IPv4地址。 您可以通过在您的kafkacat命令行中添加-X broker.address.family=v4来将地址族限制为kafkacat中的IPv4。