flume Channel选择器

本文介绍了Flume中两种内置的Channel选择器——复制选择器和多路复用选择器。复制选择器将事件复制并分发到所有Channel,而多路复用选择器根据事件报头的值选择特定的Channel进行写入。详细讨论了配置参数、配置示例以及源码分析。
摘要由CSDN通过智能技术生成

简介

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
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值