我已经在 ElasticSearch 中创建了索引和字段。
我可以使用以下命令成功运行 Logstash 配置文件,将 MySQL 数据库表中的数据添加到 ElasticSearch 中:
bin/logstash -f [PATH TO LOGSTASH CONFIG FILE] -v
我需要从我的 Java 源代码运行此命令。如何从 Java 代码运行此 Logstash 配置文件?
import java.io.*;
class UserTest{
public static void main(String[] args)
{
try
{
String s = "";
String[] cmd = new String[]{"/bin/sh", "./logstash","-f","loggingConfFile.conf"};
Process processes = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(processes.getInputStream()));
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)