http://flume.apache.org/FlumeDeveloperGuide.html#sink


看了 还是比较好上手的,简单翻译一下


sink的作用是从 Channel 提取 Event 然后传给流中的下一个 Flume Agent或者把它们存储在外部的仓库中。在Flume的配置文件中,一个 Sink 和一个唯一的 Channel 关联。有一个 SinkRunner 实例与每一个配好的 Sink 关联,当 Flume 框架调用 SinkRunner 的 start() 方法时,就创建一个新的线程来驱动这个 Sink (使用  SinkRunner 的实现Runnable接口的 PollingRunner 内部静态类来运行)。这个线程管理了 Sink 的生命周期。 Sink 需要实现 start() 和 stop() 方法。Sink 的 start() 方法需要初始化 Sink 并使它能够达到向目的地发送 Event 的状态。 Sink 的 process() 方法是处理从 Channel 传过来的 Event 和 发送 Event 的核心方法。 Sink 的 Stop() 方法需要做必要的清理工作(比如释放某些资源)。 Sink 也需要实现 Configurable 接口来处理自己的一些配置。


官网也给出了模板类:

 public class MySink extends AbstractSink implements Configurable {
private String myProp; @Override
public void configure(Context context) {
String myProp = context.getString("myProp", "defaultValue"); // Process the myProp value (e.g. validation) // Store myProp for later retrieval by process() method
this.myProp = myProp;
} @Override
public void start() {
// Initialize the connection to the external repository (e.g. HDFS) that
// this Sink will forward Events to ..
} @Override
public void stop() {
// Disconnect from the external respository and do any
// additional cleanup (e.g. releasing resources or nulling-out
// field values) ..
} @Override
public Status process() throws EventDeliveryException {
Status status = null; // Start transaction
Channel ch = getChannel();
Transaction txn = ch.getTransaction();
txn.begin(); try {
// This try clause includes whatever Channel operations you want to do
Event event = ch.take(); // Send the Event to the external repository.
// storeSomeData(e);
txn.commit();
status = Status.READY;
} catch (Throwable t) {
txn.rollback(); // Log exception, handle individual exceptions as needed
status = Status.BACKOFF; // re-throw all Errors
if (t instanceof Error) {
throw (Error) t;
}
} finally {
txn.close();
} return status;
}
}

拿来模板直接填充自己的逻辑代码即可,详细就可以直接参考HDFSSink或者HBaseSink等


flume 自定义sink的更多相关文章

  1. Hadoop生态圈-Flume的组件之自定义Sink

    Hadoop生态圈-Flume的组件之自定义Sink 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客主要介绍sink相关的API使用两个小案例,想要了解更多关于API的小技 ...

  2. Flume自定义拦截器(Interceptors)或自带拦截器时的一些经验技巧总结(图文详解)

    不多说,直接上干货! 一.自定义拦截器类型必须是:类全名$内部类名,其实就是内部类名称 如:zhouls.bigdata.MySearchAndReplaceInterceptor$Builder 二 ...

  3. [bigdata] 使用Flume hdfs sink, hdfs文件未关闭的问题

    现象: 执行mapreduce任务时失败 通过hadoop fsck -openforwrite命令查看发现有文件没有关闭. [root@com ~]# hadoop fsck -openforwri ...

  4. [Flume][Kafka]Flume 与 Kakfa结合例子(Kakfa 作为flume 的sink 输出到 Kafka topic)

    Flume 与 Kakfa结合例子(Kakfa 作为flume 的sink 输出到 Kafka topic) 进行准备工作: $sudo mkdir -p /flume/web_spooldir$su ...

  5. 【原创】大叔经验分享(54)flume kudu sink运行一段时间kudu client报错

    flume kudu sink运行一段时间报错: 19/05/05 10:15:56 WARN client.ConnectToCluster: Error receiving a response ...

  6. Flume 自定义拦截器 多行读取日志+截断

    前言: Flume百度定义如下: Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,F ...

  7. Flink自定义Sink

    Flink自定义Sink Flink 自定义Sink,把socket数据流数据转换成对象写入到mysql存储. #创建Student类 public class Student { private i ...

  8. flume自定义Source(taildirSource),自定义Sink(数据库),开发完整步骤

    一.flume简单了解推荐网站(简介包括简单案例部署): http://www.aboutyun.com/thread-8917-1-1.html 二.我的需求是实现从ftp目录下采集数据,目录下文件 ...

  9. Flume自定义Source、Sink和Interceptor(简单功能实现)

    1.Event event是flume传输的最小对象,从source获取数据后会先封装成event,然后将event发送到channel,sink从channel拿event消费. event由头he ...

随机推荐

  1. [转]Replace all UUIDs in an ATL COM DLL.

    1. Introduction. 1.1 Recently, a friend asked me for advise on a very unusual requirement. 1.2 He ne ...

  2. firefox 59 无法使用 pac 代理上网

    最近装了 firefox,电脑配置不太高,chrome 太吃内存了. 但是发现 SwitchyOmega的 pac 模式无法工作,这篇文章提到了两个思路, 其中network.dns.disableI ...

  3. fputs()

    原型:int fputs(const char *str, FILE *stream) 参数解释: const char *str : const限制函数内部修改指针指向的数据(在函数形参使用cons ...

  4. Launch VINS-Mono with Realsense D435i in RTAB-Map

    Preparation: Remap topic from D435i to rtabmap Feed the odometry to rtabmap In the rqt_graph of vins ...

  5. ueditor的bug

    1)过滤script style标签ueditor.all.jsallowDivTransToP:false ueditor.config.js,allowDivTransToP:false //允许 ...

  6. Unity---动画系统学习(6)---Avatar Mask动画融合、Layers动画分层、IK反向动力学

    1. 介绍 Avatar Mask(动画融合) 前面我们一直介绍的都是动画混合,一般用于解决边跑边转弯的问题.而动画融合一般用于解决例如边跑边挥手的问题. 简单说就是让跑步去控制腿的骨骼,挥手控制手的 ...

  7. String Reduction问题分析

    问题描述: Given a string consisting of a,b and c's, we can perform the following operation: Take any two ...

  8. Python闭包需要注意的问题

    定义   python中的闭包从表现形式上定义为:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure),也就是说内层函数引用了外层函数 ...

  9. R语言常用包汇总

    转载于:https://blog.csdn.net/sinat_26917383/article/details/50651464?locationNum=2&fps=1 一.一些函数包大汇总 ...

  10. docker 使用save和load命令来转移image

    ——假设一个image叫ubuntu—— 在本机执行sudo docker save -o ubuntu.tar ubuntu 由此得到了 ubuntu.tar 文件,将其拷贝到远程机器,执行 sud ...