flume内置的ChannelSelector有两种,分别是Replicating和Multiplexing。
Replicating类型的ChannelSelector会针对每一个Event,拷贝到所有的Channel中,这是默认的ChannelSelector。
replicating类型的ChannelSelector例子如下
1 a1.sources = r1 2 a1.channels = c1 c2 # 如果有100个Event,那么c1和c2中都会有这100个事件 3 4 a1.channels.c1.type = memory 5 a1.channels.c1.capacity = 1000 6 a1.channels.c1.transactionCapacity = 100 7 8 9 a1.channels.c2.type = memory10 a1.channels.c2.capacity = 100011 a1.channels.c2.transactionCapacity = 100
Multiplexing类型的ChannelSelector会根据Event中Header中的某个属性决定分发到哪个Channel。
multiplexing类型的ChannelSelector例子如下:
1 a1.sources = r12 3 a1.sources.source1.selector.type = multiplexing4 a1.sources.source1.selector.header = validation # 以header中的validation对应的值作为条件5 a1.sources.source1.selector.mapping.SUCCESS = c2 # 如果header中validation的值为SUCCESS,使用c2这个channel6 a1.sources.source1.selector.mapping.FAIL = c1 # 如果header中validation的值为FAIL,使用c1这个channel7 a1.sources.source1.selector.default = c1 # 默认使用c1这个channel
a1.sources.source1.selector.header = validation # 以header中的validation对应的值作为条件 同理,如下conf文件:
1 a1.sources = r1 2 a1.sinks = k1 k2 3 a1.channels = c1 c2 4 5 # Describe/configure the source 6 a1.sources.r1.type = exec 7 a1.sources.r1.command = tail -F /usr/lib/flume-ng/test.log 8 a1.sources.r1.interceptors = i1 9 a1.sources.r1.interceptors.i1.type = regex_extractor10 a1.sources.r1.interceptors.i1.regex = (\\w+):(\\w+):(\\w+)11 a1.sources.r1.interceptors.i1.serializers = s1 s2 s312 a1.sources.r1.interceptors.i1.serializers.s1.name = ip13 a1.sources.r1.interceptors.i1.serializers.s2.name = domain14 a1.sources.r1.interceptors.i1.serializers.s3.name = course15 16 a1.sources.r1.selector.type = multiplexing17 a1.sources.r1.selector.header = course18 a1.sources.r1.selector.mapping.hadoop = c119 a1.sources.r1.selector.default = c220 21 22 # Describe the sink23 a1.sinks.k1.type = file_roll24 a1.sinks.k1.channel = c125 a1.sinks.k1.sink.directory = /tmp/multiplexing/flume_sink126 27 a1.sinks.k2.type = file_roll28 a1.sinks.k2.channel = c229 a1.sinks.k2.sink.directory = /tmp/multiplexing/flume_sink230 31 # Use a channel which buffers events in memory32 a1.channels.c1.type = memory33 a1.channels.c1.capacity = 100034 a1.channels.c1.transactionCapacity = 10035 36 a1.channels.c2.type = memory37 a1.channels.c2.capacity = 100038 a1.channels.c2.transactionCapacity = 10039 40 # Bind the source and sink to the channel41 a1.sources.r1.channels = c1 c2 42 a1.sinks.k1.channel = c143 a1.sinks.k2.channel = c2
interceptor只对头部进行改变。
source r1中的头部有IP、Domain和cource三种信息,而r1的selector.header = course,表示selector只对IP,Domain和Cource中的Cource进行判断选择,然后再划分channel。