[英]kafka topic configuration using properties file
I want to configure Kafka with some topics and their unique retention settings.我想使用一些主题及其独特的保留设置来配置 Kafka。 so when I start Kafka it will load the server.properties file with those settings.
所以当我启动 Kafka 时,它将使用这些设置加载 server.properties 文件。
The only way I found was by starting Kafka, and then start and configure topics using kafka-topics.sh
script.我发现的唯一方法是启动 Kafka,然后使用
kafka-topics.sh
脚本启动和配置主题。
Example:例子:
bin/kafka-topics.sh --zookeeper zk.yoursite.com --alter --topic as-access --config retention.ms=86400000
I am using Kafka over docker, so instead of setting the entry point to be the actual script that start Kafka, I need to create my own script which will start Kafka and run some shell commands to configure those topics.我在 docker 上使用 Kafka,所以我需要创建自己的脚本来启动 Kafka 并运行一些 shell 命令来配置这些主题,而不是将入口点设置为启动 Kafka 的实际脚本。 Also if I need to create those topics on my own, I need to start and create some logic regarding topics which already exist.
此外,如果我需要自己创建这些主题,我需要开始并创建一些关于已经存在的主题的逻辑。 and I prefer not to go that road.
而且我宁愿不要go那条路。
need to create my own script which will start Kafka and run some shell commands to configure those topics
需要创建我自己的脚本来启动 Kafka 并运行一些 shell 命令来配置这些主题
wurstmeister/kafka
already supports KAFKA_CREATE_TOPICS
environment variable for this purpose为此,
wurstmeister/kafka
已经支持KAFKA_CREATE_TOPICS
环境变量
It is recommended you use a second "init container", (or shell script around docker run/compose
) that waits for the other kafka container to start and be healthy, then do topic-creation.建议您使用第二个“init container”(或 shell 脚本
docker run/compose
)等待另一个 kafka 容器启动并保持健康,然后创建主题。 Related answer相关回答
Just use AdminClient API in your client code to create topics before running producers or consumers.只需在客户端代码中使用 AdminClient API 即可在运行生产者或消费者之前创建主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.