Kafka-docker: can't produce messages

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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 

or

bin/kafka-console-producer.sh --broker-list 0.0.0.0:9092 --topic test 

I get the following error:

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

My docker-compose.yml lookes like this:

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 

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.

回答1:

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 


回答2:

Don't use local IPs like 127.0.0.1. Use the true IP instead.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!