Mel*_*goV 11 hadoop hdfs flume asp.net-web-api flume-ng
我已经构建了一个在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;
}
Run Code Online (Sandbox Code Playgroud)
Flume正在VMware虚拟机CentO上运行,这是我尝试配置水槽来监听该应用程序:
# 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
Run Code Online (Sandbox Code Playgroud)
我正在使用curl发布,这是我的尝试:
curl -X POST -H 'Content-Type: application/json; charset=UTF-8' -d '[{"ano":"2010"}]' http://transacciones.misionempresarial.com/CSharpFlume/api/SourceFlume/ObtenerValores
Run Code Online (Sandbox Code Playgroud)
我只收到这个错误:
{"Message":"Error."}
Run Code Online (Sandbox Code Playgroud)
我的问题是,这是正确的方法来配置水槽听我的网络api的http请愿,我缺少什么?
标准 Flume 'HTTPSource' 及其默认值JSONHandler只会处理特定的、以 Flume 为中心的格式的事件。
该格式记录在用户手册中,也记录在JSONHandler 源代码开头的注释中。
总之,它期望接收一个 JSON 对象列表,每个对象包含headers(键/值对,映射到 Flume Event 标头)和body(一个简单的字符串,映射到 Flume Event 主体)。
举个例子,如果您发送:
[{"headers": {}, "body": "{\"ano\":\"2010\"}"}]
Run Code Online (Sandbox Code Playgroud)
我想你会得到你想要的东西。
如果您无法灵活地更改发送的内容,那么您可以使用org.apache.flume.source.http.BLOBHandler,具体取决于您尝试执行的处理(注意。手册中没有这方面的文档,仅适用于org.apache.flume.sink.solr.morphline.BlobHandler- 它们不是同样的事情,但是FLUME-2718中有一些注释),或者您可能需要提供自己的 FlumeHTTPSourceHandler接口的实现。
附注:HTTP 源bind选项需要主机名或 IP 地址。您可能只是幸运,您的值被视为主机名,而路径被忽略。
| 归档时间: |
|
| 查看次数: |
328 次 |
| 最近记录: |