转载:https://blog.youkuaiyun.com/looklook5/article/details/40430965
Flume支持从一个源发送事件到多个通道中,这被称为事件流的复用。这里需要在配置中定义事件流的复制/复用,选择1个或者多个通道进行数据流向。
而关于selector配置前面也讲过:
<Agent>.sources.<Source1>.selector.type= replicating
这个源的选择类型为复制。这个参数不指定一个选择的时候,默认情况下复制
复用则是麻烦一下,流的事情是被筛选的发生到不同的渠道,需要指定源和扇出通道的规则,感觉与case when 类似。
复用的参数为:
<Agent>.sources.<Source1>.selector.type= multiplexing
一、复制
配置多个source,默认情况下,就是将同样的数据无差异sink到多个输出端,所以通道是复制模式。
二、复用
复用的流的事件要声明一个头部,然后我们检查头部对应的值(头部值可以在interceptor中定义)
a1.sources= r1
a1.sinks= k1 k2
a1.channels= c1 c2
#Describe/configure the source
a1.sources.r1.type= org.apache.flume.source.http.HTTPSource
a1.sources.r1.port= 50000
a1.sources.r1.host= 192.168.233.128
a1.sources.r1.selector.type= multiplexing
a1.sources.r1.channels= c1 c2
#根据头部state字段进行判断,可以在interceptor里定义
a1.sources.r1.selector.header= state
a1.sources.r1.selector.mapping.CZ= c1
a1.sources.r1.selector.mapping.US= c2
a1.sources.r1.selector.default= c1
#Describe the sink
a1.sinks.k1.type= avro
a1.sinks.k1.channel= c1
a1.sinks.k1.hostname= 192.168.233.129
a1.sinks.k1.port= 50000
a1.sinks.k2.type= avro
a1.sinks.k2.channel= c2
a1.sinks.k2.hostname= 192.168.233.130
a1.sinks.k2.port= 50000
# Usea channel which buffers events in memory
a1.channels.c1.type= memory
a1.channels.c1.capacity= 1000
a1.channels.c1.transactionCapacity= 100
a1.channels.c2.type= memory
a1.channels.c2.capacity= 1000
a1.channels.c2.transactionCapacity= 100
可以根据header中state字段的不同,推送到不同的channel中去。