gpt4 book ai didi

java - 从Java应用程序启动Flume Agent

转载 作者:行者123 更新时间:2023-12-02 21:41:18 25 4
gpt4 key购买 nike

我已经编写了一个Java应用程序,该应用程序生成水槽配置文件并将其写入Linux机器上的磁盘。然后,该应用程序将构建flume命令,并尝试通过运行以下代码中的命令来启动flume代理:

  try {
Process p = Runtime.getRuntime().exec(flumeStartCommand.toString());
p.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}

如果我使用flume命令并通过终端手动执行它,那么它将正常工作。当Java应用程序尝试执行flume命令时,什么也没有发生。这是类路径问题吗?

水槽命令在这里:
/root/flume-flume-1.6/flume-ng-dist/target/apache-flume-1.6.0-SNAPSHOT-bin/apache-flume-1.6.0-SNAPSHOT-bin/bin/flume-ng agent --conf conf --conf文件/root/flumeconfs/ConsumerGroup4.conf --name Agent_ConsumerGroup4 -Dflume.root.logger = INFO,控制台-Dflume.monitoring.type = http -Dflume.monitoring.port = 34548

我知道嵌入式代理是另一种选择,但是它们仅可用于avro接收器,这对我来说不是很有用。赞赏任何想法。
干杯,
科尔曼

最佳答案

对于其他试图弄清楚这一点的人,需要将flume命令分解为String数组中的参数,如下所示:

String[] flumeCommand = new String[]{"/root/flume-flume-1.6/flume-ng-dist/target/apache-flume-1.6.0-SNAPSHOT-bin/apache-flume-1.6.0-SNAPSHOT-bin/bin/flume-ng",
"agent",
"--conf",
"conf",
"--conf-file",
_flumeConfigurationDir+Active.getFlumeConfName(),
"--name",
Active.getFlumeAgentName(),
"-Dflume.root.logger=INFO,console",
"-Dflume.monitoring.type=http",
"-Dflume.monitoring.port="+Active.getFlumeMetricsPort(),
};

然后使用以下代码:
ProcessBuilder flumeCommandBuilder = new ProcessBuilder(flumeCommand);
File flumeConfigurationDirFile = new File(_flumeConfigurationDir);
flumeCommandBuilder.directory(flumeConfigurationDirFile);
System.out.println("Working Directory: "+ flumeCommandBuilder.directory());
flumeCommandBuilder.redirectErrorStream(true);
Process process = flumeCommandBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
System.out.println("tasklist: " + line);

关于java - 从Java应用程序启动Flume Agent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28533925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com