前几篇介绍了Flume NG Source组件的基本情况,接下来看看Channel相关的组件,Channel相关组件有:
1. Channel
2. ChannelSelector
3. Interceptor / InterceptorChain
4. ChannelProcessor
5. Transaction
这篇说说ChannelSelector。ChannelSelector的作用是为Source选择下游的Channel。有两种选择方式,复制和多路复用。所谓复制就是把Source中传递过来的Event复制给所有对应的下游的Channel。多路复用是可以把Source传递过来的Event按照不同的属性传递到不同的下游Channel中去。
下面这张图展示了ReplicatingChannelSelector的工作方式: Source中传递过来的Event会被复制到Channel1, Channel2, Channel3中去。然后不同的Channel再传递给各自下游的Sink。ChannelSelector提供了灵活的Source事件分发机制。默认的ChannelSelector就是ReplicatingChannelSelector
一个典型的配置如下: <Source1> 中的Event会被复制到下游的<Channel1>和<Channel2>中去
# List the sources, sinks and channels for the agent
<Agent>.sources = <Source1>
<Agent>.sinks = <Sink1> <Sink2>
<Agent>.channels = <Channel1> <Channel2>
# set list of channels for source (separated by space)
<Agent>.sources.<Source1>.channels = <Channel1> <Channel2>
# set channel for sinks
<Agent>.sinks.<Sink1>.channel = <Channel1>
<Agent>.sinks.<Sink2>.channel = <Channel2>
<Agent>.sources.<Source1>.selector.type = replicating
来看看ChannelSelector的接口定义
1. setChannels方法添加和Source相关的所有的Channel进来
2. getAllChannels返回和Source相关的所有Channels
3. getRequiredChannels返回的是必须要传递的Channel,当传递失败时要通知Source
4. getOpti