无法写入 kafka,broker 已关闭

Jen*_*nov 4 apache-kafka kcat

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

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
Run Code Online (Sandbox Code Playgroud)

我让 Kafka 监听端口 9092:

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 '^]'.
Run Code Online (Sandbox Code Playgroud)

以下是 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
Run Code Online (Sandbox Code Playgroud)

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

聚苯乙烯

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

/usr/local/bin/kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic Hoffman02
Created topic Hoffman02.
Run Code Online (Sandbox Code Playgroud)

但是当我使用 kafkacat 时kafkacat -b localhost:9092 -t Hoffman04 -P,它会永远挂起,但我仍然可以在日志文件夹中找到文件 Hoffman04 ls -lrt /usr/local/var/lib/kafka-logs

drwxr-xr-x  6 jenia  admin   192 28 May 11:17 Hoffman04-0
Run Code Online (Sandbox Code Playgroud)

Ede*_*ill 5

根据您的操作系统(特别是 OSX),localhost 可能会解析为 ipv4 和 ipv6 地址,而您的代理仅绑定到 IPv4 地址。-X broker.address.family=v4您可以通过添加到 kafkacat 命令行来将 kafkacat 中的地址族限制为 IPv4 。