Flume Intercept Selector配置详解
Flume配置遇到了一个问题是关于Inteceptor和Selector的问题,这篇文章主要讲解关于Inteceptor和Selector配置。
在Flume中,Source,Channel,都可以多对多,也就是,一个Source可以对应多个Channel,一个Channel可以对应多个Sink,但是一个Sink只能对应一个Channel。我给自己描绘了一个比较通俗易懂的图,来讲解一下整个Flume组件的配置。如下图所示:
在这里有2个source,2个Intercept,1个Selector,2个Channel,3个Sink,它们之间的对应关系如上图。
Source1需要经过2个Intercept,这两个Intercept是需要自定义的,在下篇文章会讲到。第一个Intercept的作用是过滤不需要的数据,第二个Intercept根据不同的Event body类型来添加Header的topic属性,用于Selector根据topic来选择发往不同的Channel。
Selector接收Intercept的Hearder有两种topic,分别是topic_start、topic_end,其中topic_start发往c1,topic_end发往c2,以下为整个图的详细配置
a1.sources = r1 r2
a1.channels = c1 c2
a1.sinks = k1 k2 k3
#r1 Source,Intercept,Selector配置
a1.sources.r1.type = com.master.source1
a1.sources.r1.channels = c1 c2
#Intercept配置
a1.sources.r1.interceptors = i1 i2
a1.sources.r1.interceptors.i1.type = com.master.myIntercept1 #自定义拦截器
a1.sources.r1.interceptors.i2.type = com.master.myIntercept2
#Selector配置
a1.sources.s1.selector.type = mutiplexing #选择Flume自带的Selector
a1.sources.s1.selector.type.header = topic
a1.sources.s1.selector.type.mapping.topic_start = c1
a1.sources.s1.selector.type.mapping.topic_end = c2
#s2配置
a1.sources.r2.type = com.master.source2
#c1 c2配置
a1.channels.c1.type = memory
a1.channels.c2.type = memory
#s1配置
a1.sinks.k1.type = com.master.mySink1
a1.sinks.k1.channel = c1
#s2配置
a1.sinks.k2.type = com.master.mySink2
a1.sinks.k1.channel = c1
#s3配置
a1.sinks.k3.type=com.master.mySink3
a1.sinks.k1.channel = c2