简体   繁体   中英

Starting Zookeeper and Kafka servers from Java application

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.

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 :

https://github.com/vert-x3/vertx-kafka-client/blob/master/src/test/java/io/vertx/kafka/client/tests/KafkaClusterTestBase.java

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM