我在本地运行 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
我让 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 '^]'.
以下是 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
我做错了什么?为什么我不能在本地 Kafka 中写一些条目?
附言
当我使用 Kafka 附带的脚本时,我可以创建主题:
/usr/local/bin/kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic Hoffman02
Created topic Hoffman02.
但是当我使用 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