以下是我给Zookeeper和Kafka Dockers的YML文件的一部分
Ive添加了“ KAFKA_CREATE_TOPICS”变量以在启动时创建主题
但是创建所有6个主题需要很长时间。所以每次我上下搬运码头工人时,我都需要等到所有创建的主题
* kafkaProducer创建主题的解决方案对我来说不是很好
当kafka / zookeeper启动时,我希望他们记住所有主题,因此我将卷添加到Zookeeper,它可以正常工作,并且该主题在启动时存在,但是由于出现以下错误,我无法使用任何主题:
“无法找到分区0的领导者”
zoo1:
image: xx.xx.xx.xx:5002/zookeeper
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
networks:
- xxnet
deploy:
restart_policy:
condition: on-failure
logging:
driver: json-file
options:
max-size: 50m
volumes:
- /home/docker-volumes/zoo1-conf/:/conf
- /home/docker-volumes/zoo1-data/:/data
- /home/docker-volumes/zoo1-datalog/:/datalog
kafka:
image: xx.xx.xx.xx:5002/wurstmeister/kafka
ports:
- 9092:9092
environment:
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181
KAFKA_ADVERTISED_HOST_NAME: xx.xx.xx.xx
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: 1600000
#KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
KAFKA_LOG_RETENTION_HOURS: 0
KAFKA_LOG_RETENTION_MINUTES: 0
KAFKA_LOG_RETENTION_MS: 120000
RETENTION.MS: 900000
ADVERTISED_HOST: kafkaserver
ADVERTISED_PORT: 9092
KAFKA_SEGMENT_BYTES: 1073741824
KAFKA_RETENTION_CHECK_INTERVAL_MS: 300000
KAFKA_CREATE_TOPICS: topic1:1:1,topic2:1:1,topic3:1:1,topic4:1:1,topic5:1:1,topic6:1:1
networks:
- xxnet
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/docker-volumes/kafka-logs/:/tmp/kafka-logs
- /home/docker-volumes/kafka-logs/kafka:/kafka
deploy:
restart_policy:
condition: on-failure
logging:
driver: json-file
options:
max-size: 50m
谢谢, 拉里