UUID拦截器,本质上也不是一个拦截器,而是在数据的headers中添加一个id字段,可以用于标记数据的唯一性。
编写配置文件uuid.conf
# a1 表示 Agent 的名称,在启动 Flume 的时候指定
# 创建一个 Source,名叫 r1
a1.sources = r1
# 创建一个 Channel,名叫 c1
a1.channels = c1
# 创建一个 Sink,名叫 k1
a1.sinks = k1
# 指定 a1 的输入源类型为端口类型,也就是数据要通过指定的端口发送
# 这里监听本地的 9999 端口
a1.sources.r1.type = netcat
a1.sources.r1.bind = m1
a1.sources.r1.port = 9999
# 这部分是新增 时间拦截器的 内容
a1.sources.r1.interceptors = i1 i2 i3 i4
a1.sources.r1.interceptors.i1.type = timestamp
# # 是否保留Event header中已经存在的同名时间戳,缺省值false
a1.sources.r1.interceptors.i1.preserveExisting= false
# # 指定Host Interceptor
a1.sources.r1.interceptors.i2.type = host
a1.sources.r1.interceptors.i3.type = static
a1.sources.r1.interceptors.i3.key = datatype
a1.sources.r1.interceptors.i3.value = music
#
# 指定UUID Interceptor
#
a1.sources.r1.interceptors.i4.type = org.apache.flume.sink.solr.morphline.UUIDInterceptor$Builder
# # 这部分是新增 时间拦截器的 内容
#
# 表示 a1 的 Channel 类型是 memory,总容量是 1000 个 Event
# 并且每收集 100 个再去提交事务
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 表示 a1 的输出是日志类型
a1.sinks.k1.type = logger
# 将 r1 和 k1 绑定到 c1 上,r1 会写入数据到 c1,然后 k1 会从 c1 读数据
a1.sources.r1.channels = c1
# 注意这里的 channel 后面没有 s,因为一个 Sink 只能绑定一个 Channel
a1.sinks.k1.channel = c1
启动flume
flume-ng agent -c $FLUME_HOME/conf -n a1 -f $FLUME_HOME/uuid.conf -Dflume.root.logger=INFO,console
发送数据
nc m1 9999
查看结果,每次发送数据不同id不同