0

我编写了一个 Java 应用程序,它构建 Flume 配置文件并将它们写入 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);
                    }                       

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

此处的 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代理 --conf conf --conf-file /root/flumeconfs/ConsumerGroup4.conf --name Agent_ConsumerGroup4 -Dflume.root.logger=INFO,console -Dflume.monitoring.type=http -Dflume.monitoring.port=34548

我知道嵌入式代理是另一种选择,但这些仅适用于对我来说不是很有用的 avro sink。欣赏任何想法。干杯,科尔曼

4

1 回答 1

0

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

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);
于 2015-02-17T23:38:08.460 回答