flume-自定义Sink基本框架

1,flume日志输出到控制台

bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/xxx.properties -Dflume.root.logger=INFO,console -Dflume.monitoring.type=http -Dflume.monitoring.port=1234

2,flume日志输出到日志文件
bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/xxx.properties -Dflume.root.logger=INFO,LOGFILE -Dflume.monitoring.type=http -Dflume.monitoring.port=1234

3conf/flume-env.sh文件的配置JVM虚拟机内存

export JAVA_OPTS="-Xms1024m -Xmx2560m -Dcom.sun.management.jmxremote"

export JAVA_HOME=/opt/jdk1.7.0_79

4,flume执行文件

a1.sources = s1
a1.channels = c1
a1.sinks = k1

# define source
a1.sources.s1.type = exec
a1.sources.s1.command = tail -F /data/xxx/xxx.log
a1.sources.s1.shell = /bin/sh -c

#define channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 4000

#a1.channels.c1.type = file
#a1.channels.c1.checkpointDir = /data/data1/flumedata/check
#a1.channels.c1.dataDirs = /data/data1/flumedata/datadir

#define selfhbase sinks
a1.sinks.k1.type=xxx.xxx.xxx.xxx
a1.sinks.k1.zoolist=cdh1:2181,cdh2:2181,cdh3:2181
a1.sinks.k1.tablename=xxxxx
a1.sinks.k1.bulkputsize=50

# define zuhe
a1.sources.s1.channels = c1
a1.sinks.k1.channel = c1


5,flume自定义sink问题

begin() called when transaction is OPEN!

//Flume-XXXsink的整体框架
public Status process() throws EventDeliveryException {
	Channel channel = getChannel();		
	try {	
		transaction = channel.getTransaction();
		transaction.begin();
					
		event = channel.take();
		if(event == null){
			break;
		}
		body = Bytes.toString(event.getBody());
		splits = body.split(",");
====================your code===========================
		transaction.commit();
	      return Status.READY;
	 } catch(IOException e){
		logger.error("ERROR Message "+e.toString());
		transaction.rollback(); // step 1
		return Status.BACKOFF; // step 2
	} catch (NullPointerException e){
		logger.info("ERROR Message null ==>"+e.toString());
		transaction.rollback(); // step 1
		return Status.BACKOFF; // step 2
	} catch (Throwable th){
 		transaction.rollback();
		if (th instanceof Error){
			throw (Error) th;
		}else{
		       throw new EventDeliveryException(th);
		}
	}finally {
		try {
			this.table.put(this.hbasePutList); 
		} catch (IOException e) {
			logger.error("", e);
		}
		this.hbasePutList.clear(); 
		transaction.close(); 	//一定是等流程处理完成后才close()
        }

注意,要在transaction.close()之前操作transaction.rollback()或是transaction.commit()



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值