问题描述
我正试图让Kafka首次在docker-compose上工作。该应用程序在没有docker的情况下运行良好。但是在docker上,出现如下所述的错误。为什么卡夫卡会抛出此错误?
错误:
我的docker-compose配置:
版本:'3.3'
服务:
动物园管理员:
图片:wurstmeister / zookeeper
端口:
- 2181:2181
kafka:
图片:wurstmeister / kafka
命令:[start-kafka.sh]
环境:
KAFKA_ZOOKEEPER_CONNECT:zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME:192.168.23.134
KAFKA_CREATE_TOPICS:电子邮件令牌:1:1
数量:
-/ var /run/docker.sock:/var/run/docker.sock
端口:
- 9092:9092
取决于:
-动物园管理员
电子邮件服务:
构建:./电子邮件服务
环境:
SPRING_KAFKA_BOOTSTRAPSERVERS:kafka:90 92
端口:
- 8081:8081
取决于:
-kafka
正如您对问题的评论中所述,问题似乎出在Kafka经纪人的广告名称上。根据您的docker-compose,您应该使用 192.168.23.134
,但是您的电子邮件服务使用的是 kafka:9092
。您可以尝试使用此docker-compose。我用 confluentinc
提供的最新Zookeeper和Kafka替换了wurstmeister服务,并添加了您的电子邮件服务。
---
版本: 2
服务:
动物园管理员:
图片:confluentinc / cp-zookeeper:最新
环境:
ZOOKEEPER_CLIENT_PORT:2181
ZOOKEEPER_TICK_TIME:2000
kafka:
图片:confluentinc / cp -kafka:最新
取决于:
-zookeeper
端口:
-9092:9092
环境:
KAFKA_BROKER_ID:1
KAFKA_ZOOKEEPER_CONNECT:zookeeper :2181
KAFKA_ADVERTISED_LISTENERS:PLAINTEXT:// kafka:29092,PLAINTEXT_HOST:// localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP:PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ATION_LIST_LIC_LIC_LIC_LIC_LIC_NAME_LIC_LIC_FREE:
电子邮件服务:
构建:./email-service
环境:
SPRING_KAFKA_BOOTSTRAPSERVERS:kafka:29092
端口:
- 8081:8081
取决于:
-kafka
请注意, KAFKA_ADVERTISED_HOST_NAME
已过时,建议改用 KAFKA_ADVERTISED_LISTENERS
。有关 KAFKA_ADVERTISED_LISTENERS
的详细信息,请在。 / p>
I'm trying to get Kafka to work on docker-compose for the first time. The application runs fine without docker. But on docker, I get the error as described below. Any reason why Kafka would throw this error?
The error:
My docker-compose config:
version: '3.3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
command: [start-kafka.sh]
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: 192.168.23.134
KAFKA_CREATE_TOPICS: "email-token:1:1"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "9092:9092"
depends_on:
- zookeeper
email-service:
build: ./email-service
environment:
SPRING_KAFKA_BOOTSTRAPSERVERS: kafka:9092
ports:
- "8081:8081"
depends_on:
- kafka
As stated in the comments to your question the problem seems to be with the advertised name for the Kafka broker. According to your docker-compose you should be using 192.168.23.134
but your email-service is using kafka:9092
. You can try with this docker-compose. I replaced the wurstmeister services with the latest Zookeeper and Kafka provided by confluentinc
and added your email-service.
---
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
email-service:
build: ./email-service
environment:
SPRING_KAFKA_BOOTSTRAPSERVERS: kafka:29092
ports:
- "8081:8081"
depends_on:
- kafka
Please note that KAFKA_ADVERTISED_HOST_NAME
has been deprecated and it's recommended to use KAFKA_ADVERTISED_LISTENERS
instead. For more information about KAFKA_ADVERTISED_LISTENERS
check here.
这篇关于为什么卡夫卡会警告“分区的领导者经纪人没有匹配的听众”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!