Flume NG源码分析(七)ChannelSelector

本文深入分析了Flume NG中的ChannelSelector组件,其功能在于为Source选择合适的下游Channel。ChannelSelector有两种策略:复制(将Event复制到所有下游Channel)和多路复用(根据Event属性选择特定Channel)。文中详细阐述了ReplicatingChannelSelector的工作原理,并给出了配置示例,以及MultiplexingChannelSelector如何根据Event Header属性进行动态选择。
摘要由CSDN通过智能技术生成

前几篇介绍了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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值