Write a custom HTTPSource Handler for Flume-ng

北城余情 提交于 2019-12-24 00:59:52

问题


Are there any resources available to help me out in writing a custom handler for a HTTPSource for Flume-ng. I read the documentation and there is a sample handler for Json but I am wondering if anybody has had the need to write a handler for creating Flume events from a XML message body. The HttpSource is now available in Flume-ng 1.3.1 but we need handlers to interpret our data.

Thanks.


回答1:


Did you look at JSONHandler source? The only difference for XMLHandler would be usage of some XML deserializer instead of Gson.

You just need to convert something like:

<dataList>
  <data>
     ...
  </data>
  <data>
     ...
  </data>      
</dataList>

into List<SimpleEvent> (or introduce your own HTTPEvent, as Flume developers did with JSONEvent, if you need to handle different encodings). These events' bodies will contain your <data>..</data> chunks as byte representation of String.

I don't recommend to implement any additional business logic of parsing these events in Flume, because business rules tends to change often and Flume as infrastructure software should be stable.

Finally, you pack your code into jar, place this jar into Flume's lib directory (/usr/lib/flume-ng/lib in case of Cloudera's rpm distribution), specify in flume.conf "handler" property of HTTPSource as "com.vicky.flume.source.http.XMLHandler" (or something like that), restart the agent and that's all.

Hope this helps. Will be glad to answer your questions.



来源:https://stackoverflow.com/questions/14275153/write-a-custom-httpsource-handler-for-flume-ng

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!