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.
-
Configure them as windows services: https://stackoverflow.com/questions/36309844/install-kafka-as-windows-service – Erwin Bolwidt Jun 17 '17 at 09:18
-
thanks for the hint, but this just says how to install ZK and K, while I would need to launch them by Java and not the cmd. – sirdan Jun 17 '17 at 09:28
-
It doesn't tell you how to install them, it tells you how to configure them as windows services. So that you don't have to start and stop them every time you need to start the consumer application. That's the proper way to handle a service. You haven't given an indication in your question *why* you think you need to start it from Java - you've only hinted that you find having to start it manually inconvenient. – Erwin Bolwidt Jun 17 '17 at 12:30
3 Answers
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 ;)

- 9,431
- 1
- 30
- 45
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?

- 91
- 6
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

- 2,293
- 1
- 18
- 26