自定义flume-source
来源:互联网 发布:linux server 版本 编辑:程序博客网 时间:2024/06/08 04:17
package com.bigdata.flume;import org.apache.flume.Context;import org.apache.flume.Event;import org.apache.flume.EventDeliveryException;import org.apache.flume.PollableSource;import org.apache.flume.conf.Configurable;import org.apache.flume.event.EventBuilder;import org.apache.flume.source.AbstractSource;import java.nio.charset.Charset;import java.util.HashMap;import java.util.Random;/** * */public class MySource extends AbstractSource implements Configurable, PollableSource { @Override public void configure(Context context) { } @Override public Status process() throws EventDeliveryException { Status status = null; try{ Random random = new Random(); int randomNum = random.nextInt(100); String text = "Hello World :" + random.nextInt(100); HashMap<String, String> header = new HashMap<String, String>(); header.put("id", random+""); this.getChannelProcessor() .processEvent(EventBuilder.withBody(text, Charset.forName("UTF-8"), header)); status = Status.READY; }catch (Throwable t) { // Log exception, handle individual exceptions as needed status = Status.BACKOFF; // re-throw all Errors if (t instanceof Error) { throw (Error)t; } } return status; }}
2.flume-source.conf
#a1.sources=r1a1.sinks=k1a1.channels=c1 #a1.sources.r1.type=com.bigdata.flume.MySource #a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100a1.channels.c1.byteCapacityBufferPercentage=20a1.channels.c1.byteCapacity=800000 #a1.sinks.k1.type=file_roll#注意目录得是虚拟机上的a1.sinks.k1.sink.directory=/tmp/a # a1.sources.r1.channels=c1a1.sinks.k1.channel=c1#运行命令bin/flume-ng agent --conf conf --name a1 --conf-file conf/fulme-source.conf -Dflume.root.logger=INFO,console3.结果
阅读全文
0 0
- flume自定义sink source
- flume自定义source
- flume自定义source
- 自定义flume-source
- flume学习(八):自定义source
- flume学习(七):自定义source
- flume 自定义source,sink,channel,拦截器
- Flume Source
- Flume Source
- Flume整合mysql碰到的自定义source表名问题
- Flume自定义Source、Sink和Interceptor(简单功能实现)
- flume之Http Source
- 2. Flume Source 详解
- flume框架 source简介
- flume之kafka source
- Flume Source 实例
- flume学习(七)、(八):如何使用event header中的key值以及自定义source
- flume学习(七)、(八):如何使用event header中的key值以及自定义source
- nyoj811变态最大值
- Mybatis绑定错误的原因
- 基础的Linux操作命令
- 华为2
- 大学生职业规划
- 自定义flume-source
- 数据结构——串—串的模式匹配算法
- new collections
- 树状数组 (模板)
- RegExp对象
- 转发和重定向
- 指针修改const
- Linux下(Ubuntu14.04)安装Opencv3.3.0
- 几种简单范数介绍