我使用Apache/Kafka的官方镜像。
我想从主机连接到 Kafka。
这个 Docker-compose 效果很好:
services:
broker:
image: apache/kafka:latest
ports:
- 9094:9094
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_NUM_PARTITIONS: 5
如你所见,我在这里使用端口 9094。
PS D:\Docker\docker-compose\kafka> kafka-topics.bat --bootstrap-server localhost:9094 --create --topic temperature
Created topic temperature.
但是如果我将端口更改为 9092,哪个是 Kafka 的默认端口:
services:
broker:
image: apache/kafka:latest
ports:
- 9092:9092
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://:9094,CONTROLLER://:9093,EXTERNAL://:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9094,EXTERNAL://localhost:9092
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_NUM_PARTITIONS: 5
我更改了这些行:
9092:9092
...
KAFKA_LISTENERS:纯文本://:9094,控制器://:9093,外部://:9092
KAFKA_ADVERTISED_LISTENERS:纯文本://kafka:9094,EXTERNAL://localhost:9092
它停止工作。
PS D:\Docker\docker-compose\kafka> kafka-topics.bat --bootstrap-server localhost:9092 --create --topic temperature
Error while executing topic command : Timed out waiting for a node assignment. Call: createTopics
[2024-11-09 16:08:51,190] ERROR org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment. Call: createTopics
(org.apache.kafka.tools.TopicCommand)
怎么会呢?为什么会发生这样的事?
更新
我什至尝试了来自 Apache/Kafka github 的官方 docker-compose: https://github.com/apache/kafka/blob/trunk/docker/examples/docker-compose-files/single-node/plaintext/docker-compose .yml
它也不适用于端口 9092,但我在 9097 端口上更改了它,宾果它又可以工作了。 9092端口有什么问题?
与 bitnami 图像相同。
我发现我的电脑有问题。
我有 netsh 配置,将 localhost:9092 重定向到
我在尝试在 WSL 上设置 Kafka 时进行了此配置,但完全忘记了此配置。