如何使用java程序执行flume配置文件?

whitzsjs  于 2021-06-03  发布在  Flume
关注(0)|答案(1)|浏览(335)

我有一个Flume配置文件 filename.conf ,当我在终端执行这个文件时,它工作得很好。但是我尝试在java程序中使用 Runtime.getRuntime().exec 功能不起作用。
这是我的 flume 执行命令:

/home/path/flume/bin/flume-ng agent --conf-file /home/path/flume/filename.conf --name Agent -Dflume.root.logger=INFO,console

这是我的java代码:

Process p;

p = Runtime.getRuntime().exec("/home/path/flume/bin/flume-ng agent --conf-file   /home/path/flume/filename.conf --name TwitterAgent -Dflume.root.logger=INFO,console");

p.waitFor();

BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

String line = "";

while ((line = reader.readLine())!= null) 
{
System.out.println(line);
}

我没有得到任何错误。

cbeh67ev

cbeh67ev1#

flume提供了一个应用程序类来使用java程序运行conf文件。请查找以下程序。

import org.apache.flume.node.Application;
import org.apache.log4j.BasicConfigurator;

public class flume {
    public static void main(String[] args)
    {
        String[] args1 = new String[] { "agent","-nTwitterAgent","-fflume.conf" };
        BasicConfigurator.configure();
        Application.main(args1);
        System.setProperty("hadoop.home.dir", "/");
   }
}

在应用程序类中,需要提供代理、agentname和flume.conf文件路径。在我的例子中,flume.conf文件只在我的项目类路径中,所以我刚刚指定为-fflume.conf。如果它在不同的目录中,则需要在那里指定完整路径。在此之后,您可以将其作为普通java程序本身运行。

相关问题