I am using a Java application which start a consumer reading Kafka topics. Every time I need to start the consumer application, I have to start the Zookeeper and Kafka servers with commands in cmd. Is it possible to start/stop them with small Java programs? Thank you.
Please see this topic, it's about starting Zookeeper in Java:
Best way to start zookeeper server from java program
directing to this:
Is it possible to start a zookeeper server instance in process, say for unit tests?
If you need this for something like testing the I think that the better way is using the Debezium library which provides a KafkaCluster embedded implementation. You can see how we use it in the Vert.x Kafka Client project for unit testing here :
Take a look around that ;)
To start up a Kafka cluster for your tests, you can use the following wrapper: https://www.testcontainers.org/modules/kafka/
See also this project which integrates Kafka further in the context of a Spring application: https://github.com/vspiliop/embedded-kafka-cluster
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.