Flume NG源码分析(三)使用Event接口表示数据流
来源:互联网 发布:手机游戏网络加速器 编辑:程序博客网 时间:2024/06/01 10:25
Flume NG有4个主要的组件:
Event表示在Flume各个Agent之间传递的数据流
Source表示从外部源接收Event数据流,然后传递给Channel
Channel表示对从Source传递的Event数据流的临时存储
Sink表示从Channel中接收存储的Event数据流,并传递给下游的Source或者终点仓库
这篇看一下Event接口表示的数据流。Source, Channel, Sink操作的数据流都是基于Event接口的封装。
public interface Event { /** * Returns a map of name-value pairs describing the data stored in the body. */ public Map<String, String> getHeaders(); /** * Set the event headers * @param headers Map of headers to replace the current headers. */ public void setHeaders(Map<String, String> headers); /** * Returns the raw byte array of the data contained in this event. */ public byte[] getBody(); /** * Sets the raw byte array of the data contained in this event. * @param body The data. */ public void setBody(byte[] body);}
Event接口非常简单,数据流分为两个部分:消息头和消息体。消息头是一个Key-Value的,存储字符串的结构。消息体是普通的字节数组。
Event的类层次结构如下
来看一下常用的SimpleEvent的具体实现,ExecSource等组件都是使用它来封装本地日志数据。它的实现非常简单,就是设置了header和body两部分数据。
public class SimpleEvent implements Event { private Map<String, String> headers; private byte[] body; public SimpleEvent() { headers = new HashMap<String, String>(); body = new byte[0]; } @Override public Map<String, String> getHeaders() { return headers; } @Override public void setHeaders(Map<String, String> headers) { this.headers = headers; } @Override public byte[] getBody() { return body; } @Override public void setBody(byte[] body) { if(body == null){ body = new byte[0]; } this.body = body; } @Override public String toString() { Integer bodyLen = null; if (body != null) bodyLen = body.length; return "[Event headers = " + headers + ", body.length = " + bodyLen + " ]"; }}
看一下如何创建Event对象实例
public class EventBuilder { /** * Instantiate an Event instance based on the provided body and headers. * If <code>headers</code> is <code>null</code>, then it is ignored. * @param body * @param headers * @return */ public static Event withBody(byte[] body, Map<String, String> headers) { Event event = new SimpleEvent(); if(body == null) { body = new byte[0]; } event.setBody(body); if (headers != null) { event.setHeaders(new HashMap<String, String>(headers)); } return event; }}
0 0
- Flume NG源码分析(三)使用Event接口表示数据流
- 【Java】【Flume】Flume-NG启动过程源码分析(三)
- 【Java】【Flume】Flume-NG启动过程源码分析(三)
- Flume NG源码分析(七)ChannelSelector
- 【Java】【Flume】Flume-NG启动过程源码分析(一)
- 【Java】【Flume】Flume-NG启动过程源码分析(二)
- 【Java】【Flume】Flume-NG启动过程源码分析(一)
- 【Java】【Flume】Flume-NG启动过程源码分析(一)
- 【Java】【Flume】Flume-NG启动过程源码分析(二)
- Flume-ng MemoryChannel 源码分析
- 【Flume】【源码分析】深入flume-ng的三大组件——source,channel,sink
- 【Flume】【源码分析】深入flume-ng的三大组件——source,channel,sink
- 【Flume】【源码分析】深入flume-ng的三大组件——source,channel,sink
- Flume NG源码分析(四)使用ExecSource从本地日志文件中收集日志
- Flume NG源码分析(五)使用ThriftSource通过RPC方式收集日志
- Flume NG源码分析(六)应用程序使用的RpcClient设计
- 日志收集之flume-ng源码分析
- 日志收集之flume-ng源码分析
- 修改Tomcat默认编码
- Java创建二叉树及其遍历的递归和非递归实现
- android bluedroid调试
- UVA 11054 - Wine trading in Gergovia
- Repo 下载路径
- Flume NG源码分析(三)使用Event接口表示数据流
- Qt开发ActiveX及环境搭建
- C++中的单例模式
- Windows Server2012 虚拟机复制及故障转移(Part4)
- Ubuntu系统如何安装双网卡及更改网卡名称(eth0改为eth1)
- 探访美国创客空间之TechShop:商业化的迷你工厂
- objective-c怎么将一个字符串分割成多个字符串
- Android Volley完全解析(一),初识Volley的基本用法
- 欢迎使用CSDN-markdown编辑器