我已经构建了一个发布在IIS服务器上的api web应用程序,我正在尝试配置Apache Flume来侦听该web api并将http请求的响应保存在HDFS中,这是我需要侦听的post方法:
[HttpPost]
public IEnumerable<Data> obtenerValores(arguments arg)
{
Random rdm = new Random();
int ano = arg.ano;
int rdmInt;
decimal rdmDecimal;
int anoActual = DateTime.Now.Year;
int mesActual = DateTime.Now.Month;
List<Data> ano_mes_sales = new List<Data>();
while (ano <= anoActual)
{
int mes = 1;
while ((anoActual == ano && mes <= mesActual) || (ano < anoActual && mes <= 12))
{
rdmInt = rdm.Next();
rdmDecimal = (decimal)rdm.NextDouble();
Data anoMesSales = new Data(ano, mes,(rdmInt * rdmDecimal));
ano_mes_sales.Add(anoMesSales);
mes++;
}
ano++;
}
return ano_mes_sales;
}Flume在VMware虚拟机CentOs上运行,这是我尝试配置flume以侦听该应用程序:
# Sources, channels, and sinks are defined per # agent name, in this case 'tier1'.
a1.sources = source1
a1.channels = channel1
a1.sinks = sink1
a1.sources.source1.interceptors = i1 i2
a1.sources.source1.interceptors.i1.type = host
a1.sources.source1.interceptors.i1.preserveExisting = false
a1.sources.source1.interceptors.i1.hostHeader = host
a1.sources.source1.interceptors.i2.type = timestamp
# For each source, channel, and sink, set # standard properties.
a1.sources.source1.type = org.apache.flume.source.http.HTTPSource
a1.sources.source1.bind = transacciones.misionempresarial.com/CSharpFlume
a1.sources.source1.port = 80
# JSONHandler is the default for the httpsource #
a1.sources.source1.handler = org.apache.flume.source.http.JSONHandler
a1.sources.source1.channels = channel1
a1.channels.channel1.type = memory
a1.sinks.sink1.type = hdfs
a1.sinks.sink1.hdfs.path = /monthSales
a1.sinks.sink1.hdfs.filePrefix = event-file-prefix-
a1.sinks.sink1.hdfs.round = false
a1.sinks.sink1.channel = channel1
# Other properties are specific to each type of # source, channel, or sink. In this case, we # specify the capacity of the memory channel.
a1.channels.channel1.capacity = 1000 我正在使用curl来发布,这是我的尝试:
curl -X POST -H 'Content-Type: application/json; charset=UTF-8' -d '[{"ano":"2010"}]' http://transacciones.misionempresarial.com/CSharpFlume/api/SourceFlume/ObtenerValores我只得到这个错误:
{"Message":"Error."}我的问题是,哪种正确的方式配置flume来监听http请求我的web api,我错过了什么?
发布于 2019-05-13 23:25:23
标准的Flume 'HTTPSource‘及其默认JSONHandler将只处理特定的、以Flume为中心的格式的事件。
这种格式记录在in the user manual中,也记录在JSONHandler source code开头的注释中。
总而言之,它希望收到一个JSON对象列表,每个对象都包含headers (键/值对,映射到Flume事件头部)和body (一个简单字符串,映射到Flume事件主体)。
以您的示例为例,如果您发送:
[{"headers": {}, "body": "{\"ano\":\"2010\"}"}]我想你会得到你想要的。
如果您没有更改发送内容的灵活性,那么您可以使用org.apache.flume.source.http.BLOBHandler,这取决于您尝试进行的处理(NB。手册中没有这方面的文档,只是针对org.apache.flume.sink.solr.morphline.BlobHandler的-它们不是一回事,但在FLUME-2718中有一些说明),或者您可能需要提供您自己的Flume的HTTPSourceHandler接口的实现。
旁注: HTTP Source bind选项需要一个主机名或IP地址。您可能只是幸运,因为您的值被视为主机名,而路径被忽略。
https://stackoverflow.com/questions/46547046
复制相似问题