我在 Windows 机器上本地运行 kafka。我运行 kafka 的方式是使用
.\bin\windows\kafka-server-start.bat .\config\server.properties
Run Code Online (Sandbox Code Playgroud)
server.properties 是:
listeners=Listener_BOB://:29092,Listener_Kafkacat://127.0.0.1:9092
advertised.listeners=Listener_BOB://:29092,Listener_Kafkacat://127.0.0.1:9092
listener.security.protocol.map=Listener_BOB:PLAINTEXT,Listener_Kafkacat:PLAINTEXT
inter.broker.listener.name=Listener_BOB
Run Code Online (Sandbox Code Playgroud)
我正在使用 docker 运行 kafkacat
docker run -it --network="host" --name="producer" confluentinc/cp-kafkacat bash
Run Code Online (Sandbox Code Playgroud)
当我跑
kafkacat -b host.docker.internal:9092 -C -t test
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
% ERROR: Local: Broker transport failure: 127.0.0.1:9092/0: Connect to ipv4#127.0.0.1:9092 failed: Connection refused (after 0ms in state CONNECT)
Run Code Online (Sandbox Code Playgroud)
我知道我可以在 docker 中运行 Kafka,但我想知道为什么我无法连接到代理并生成或使用消息。我尝试了不同的方法并试图了解听众在做什么,但我无法理解为什么这不起作用。
当我做
kafkacat -b host.docker.internal:9092 -t test -L
Run Code Online (Sandbox Code Playgroud)
我得到
1 brokers:
broker 0 at 127.0.0.1:9092
1 topics:
topic "test" with 1 partitions:
partition 0, leader 0, …Run Code Online (Sandbox Code Playgroud)