[英]How to fetch list of all ConsumerGroup from the Kafka Server(Not Zookeeper) in Java
[英]Spring Boot start Zookeeper and Kafka Server from Java
到目前为止,在运行Spring Boot应用程序之前,我已经从命令行启动了zookeeper和kafka服务器,但是现在我需要直接从代码中启动它们。
首先,我尝试在main方法内部使用ProcessBuilder:
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);
}
但这似乎不起作用,因为控制台上什么也没打印,并且一段时间后应用程序抛出TimeOutException。
其次,我想让Zookeeper启动后运行kafka服务器。 一个人怎么能做到这一点?
您将必须使用ZookeeperExecutor
从“您的” Java应用程序中启动Zookeeper API,方法是提供4个初始参数和一个线程运行器。 ZooKeeper API文档https://zookeeper.apache.org/doc/r3.4.13/javaExample.html和https://www.programcreek.com/java-api-examples/?api=org.apache上给出了一个示例.zookeeper.server.ZooKeeperServerMain
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.