Kafka-docker:无法产生消息 [英] Kafka-docker: can't produce messages
问题描述
我使用该项目在docker容器中设置了kafka https://github.com/wurstmeister/ kafka-docker 。我可以成功地在其上创建并列出主题,但是一旦我尝试使用以下任一方法生成一条消息
I set up kafka in a docker container using this project https://github.com/wurstmeister/kafka-docker. I can successfully create and list topics on it, but once I try to produce a message with either
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
或
bin/kafka-console-producer.sh --broker-list 0.0.0.0:9092 --topic test
我收到以下错误:
ERROR向主题测试发送消息时出现错误,键为:空,值:
4个字节,错误为:
(org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache。 kafka.common.errors.TimeoutException:测试0的1条记录
过期:自创建批处理后再经过1536 ms
ERROR Error when sending message to topic test with key: null, value: 4 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback) org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for test-0: 1536 ms has passed since batch creation plus linger time
我的 docker-compose.yml 看起来像这样:
version: '2'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
build: .
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: docker.for.mac.localhost
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
我为 KAFKA_ADVERTISED_HOST_NAME 属性尝试了其他选项,包括 docker.for.mac.localhost ,应该将其解析为实际的Docker主机。 ip和 0.0.0.0 ,但结果相同。
I tried different options for the KAFKA_ADVERTISED_HOST_NAME property, including docker.for.mac.localhost which is supposed to be resolved as the actual docker host ip, and 0.0.0.0, but the result is the same.
推荐答案
您可以尝试这个docker-compose,对我有用:
You can try with this docker-compose, it's working for me:
version: '2'
services:
zookeeper:
image: wurstmeister/zookeeper
stdin_open: true
tty: true
ports:
- 2181:2181/tcp
kafka:
image: wurstmeister/kafka:0.11.0.1
environment:
KAFKA_CREATE_TOPICS: test:1:1
KAFKA_ZOOKEEPER_CONNECT: <<HOST_IP>>:2181
KAFKA_ADVERTISED_HOST_NAME: <<HOST_IP>>
KAFKA_ADVERTISED_PORT: '9092'
KAFKA_BROKER_ID: '999'
stdin_open: true
tty: true
links:
- zookeeper:zookeeper
ports:
- 9092:9092/tcp
这篇关于Kafka-docker:无法产生消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!