Until now I've started zookeeper and kafka server from command line before running my Spring Boot application, but now I need to start them directly from code.
First thing is, I've tried using ProcessBuilder inside main method:
Process process = new ProcessBuilder("C:\\kafka_2.12-2.2.0\\bin\\windows\\zookeeper-server-start.bat",
"C:\\kafka_2.12-2.2.0\\config\\zookeeper.properties").start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
But this seems not working, since nothing is printed on the console and after a while the application throws a TimeOutException.
Second, I would like to have the kafka server to run after Zookeeper has started; how can one achieve this?