简介
channel处理器用于决定source接收的时间写入哪个channel,由其通知channel,并将时间写入。
选择器类型
flume自带两种选择器:
1.relicating(复制选择器),默认使用
2.multiplexing(多路复用选择器)
1.复制选择器
复制选择器会复制每个source接收的事件,将事件复制并分发到所有channel,可通过配置参数,控制分发的channel。
配置参数
参数 | 描述 |
---|---|
type | replicating |
optional | channel名(即channel可选,失败时不会再次发送) |
配置示例:
agent.sources.s1.type=avro
agent.sources.s1.channels = c1 c2 c3
agnet.sources.s1.selector.type=relicating
agent.sources.s1.selector.optional= c3
按上面配置,当source写c3失败时,不会抛出ChannelException异常,因此c3也不会导致source发送重试。
源码分析:
/**
* Replicating channel selector. This selector allows the event to be placed
* in all the channels that the source is configured with.
*/
public class ReplicatingChannelSelector extends org.apache.flume.channel.AbstractChannelSelector {
/**
* Configuration to set a subset of the channels as optional.
*/
public static final String CONFIG_OPTIONAL = "optional";
List<Channel> requiredChannels = null;
List<Channel> optionalChannels = new ArrayList<Channel>();
@Override
//返回所有除option的channel列表
public List<Channel> getRequiredChannels(Event event) {
/*
* Seems like there are lot of components within flume that do not call
* configure method. It is conceiveable that custom component tests too
* do that. So in that case, revert to old behavior.
*/
if (requiredChannels == null) {
return getAllChannels();
}
return requiredChannels;
}
@Override
//返回所有option channel列表
public List<Channel> getOptionalChannels(Event event) {
return optionalChannels;
}
@Override
public void configure(Context context) {
String optionalList = context.getString(CONFIG_OPTIONAL);
requiredChannels = new ArrayList<Channel>(getAllChannels());
Map<String, Channel