|NO.Z.00048|——————————|BigDataEnd|——|Hadoop&Flume.V11|——|Flume.v11|高级特性|拦截器|高可用|选择器.v03|
一、选择器
### --- 选择器
~~~ source可以向多个channel同时写数据,所以也就产生了以何种方式向多个channel写的问题:
~~~ replication(复制,缺省)。数据完整地发送到每一个channel;
~~~ multiplexing(多路复用)。通过配置来按照一定的规则进行分发;
### --- 复制选择器:默认的选择器。
~~~ 上面这个例子中,c3配置成了可选的。向c3发送数据如果失败了会被忽略。
~~~ c1和c2没有配置成可选的,向c1和c2写数据失败会导致事务失败回滚。
a1.sources = r1
a1.channels = c1 c2 c3
a1.sources.r1.selector.type = replicating
a1.sources.r1.channels = c1 c2 c3
a1.sources.r1.selector.optional = c3

### --- 多路复用选择器
a1.sources = r1
a1.channels = c1 c2 c3 c4
a1.sources.r1.selector.type = multiplexing
a1.sources.r1.selector.header = state #以每个Event的header中的state这个属性的值作为选择channel的依据
a1.sources.r1.selector.mapping.CZ = c1 #如果state=CZ,则选择c1这个channel
a1.sources.r1.selector.mapping.US = c2 c3 #如果state=US,则选择c2 和 c3 这两个channel
a1.sources.r1.selector.default = c4 #默认使用c4这个channel

### --- 自定义选择器
~~~ 自定义选择器就是开发一个 org.apache.flume.ChannelSelector 接口的实现类。
~~~ 实现类以及依赖的jar包在启动时候都必须放入Flume的classpath。
a1.sources = r1
a1.channels = c1
a1.sources.r1.selector.type =
org.liyifeng.flume.channel.MyChannelSelector

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号