1. 实现interceptor接口,并实现其方法,接口完全限定名为:org.apache.flume.interceptor.Interceptor;
2. 自定义拦截器内部添加静态内部类,实现Builder接口,并实现其方法,接口完全限定名为:Interceptor.Builder
3. 将自定义拦截器打包,上传,我使用的是CDH,自定义拦截器jar包位置为:/opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/lib/flume-ng/lib,如果使用的原生的flume,大家自行查询自定义拦截器jar包存放位置即可。
4. 编写flume配置文件,下面是示例代码:
#agent
customInterceptor.sources=r1
customInterceptor.channels=c1
customInterceptor.sinks=s1
#source
customInterceptor.sources.r1.type=spooldir
customInterceptor.sources.r1.spoolDir=/home/jumpserver/flume/data1
customInterceptor.sources.r1.consumeOrder=youngest
customInterceptor.sources.r1.recursiveDirectorySearch=false
customInterceptor.sources.r1.deletePolicy=immediate
customInterceptor.sources.r1.pollDelay=500
#source1-interceptor
customInterceptor.sources.r1.interceptors=i1
customInterceptor.sources.r1.interceptors.i1.type=cn.com.bonc.interceptor.CustomInterceptor$Builder
customInterceptor.sources.r1.interceptors.i1.param=parameter
#channe1
customInterceptor.channels.c1.type=memory
customInterceptor.channels.c1.capacity=1000
customInterceptor.channels.c1.transactionCapacity=100
#sink
customInterceptor.sinks.s1.type=logger
#package
customInterceptor.sources.r1.channels=c1
customInterceptor.sinks.s1.channel=c1
完整参考:https://blog.youkuaiyun.com/u012443641/article/details/80757229