|NO.Z.00046|——————————|BigDataEnd|——|Hadoop&Flume.V09|——|Flume.v09|高级特性|拦截器|高可用|选择器.v01|

一、高级特性
### --- [数据采集工具-Flume]

~~~     [Flume高级特性之拦截器]
~~~     [Flume高级特性之选择器,Sink组逻辑处理器]
~~~     [Flume高级特性之事务机制及可靠性]
~~~     [Flume高可用] 
### --- 拦截器

~~~     Flume支持在运行时对event进行修改或丢弃,通过拦截器来实现;
~~~     Flume里面的拦截器是实现了org.apache.flume.interceptor.Interceptor 接口的类;
~~~     拦截器可以根据配置 修改 甚至 丢弃 event;
~~~     Flume也支持链式的拦截器执行方式,在配置文件里面配置多个拦截器就可以了;
~~~     拦截器的顺序取决于它们配置的顺序,Event 按照顺序经过每一个拦截器;
### --- 时间添加戳拦截器

~~~     这个拦截器会向每个event的header中添加一个时间戳属性进去,
~~~     key默认是“timestamp ”(也可以通过下面表格中的header来自定义),
~~~     value就是当前的毫秒值(其实就是用System.currentTimeMillis()方法得到的)。
~~~     如果event已经存在同名的属性,可以选择是否保留原始的值。
属性 默认值 解释
type - timestamp
header timestamp 向event header中添加时间戳键值对的key
preserveExisting false 是否保留event header中已经存在的同名
(上面header设置的key,默认是timestamp)时间戳
二、时间添加拦截器测试:
### --- 再次运行 入门案例 中的测试,观察 event header信息
~~~     可以看见 header 为空

[root@linux123 ~]#  $FLUME_HOME/bin/flume-ng agent --name a1 \
--conf-file $FLUME_HOME/conf/flume-netcat-logger.conf \
-Dflume.root.logger=INFO,console
~~输出参数
INFO sink.LoggerSink: Event: { headers:{} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 0D             hello world. }
INFO sink.LoggerSink: Event: { headers:{} body: 31 0D                                           1. }
INFO sink.LoggerSink: Event: { headers:{} body: 32 0D                                           2. }
INFO sink.LoggerSink: Event: { headers:{} body: 33 0D                                           3. }
INFO sink.LoggerSink: Event: { headers:{} body: 34 0D                                           4. }
INFO sink.LoggerSink: Event: { headers:{} body: 35 0D                                           5. }

[root@linux123 ~]#  telnet linux123 8888
hello world
 1
 2
 3
 4
 5
//  输入 hello world
### --- 在入门案例的基础上,在配置文件中增加时间拦截器的配置。命名为timestamp.conf

[root@linux123 ~]# vim $FLUME_HOME/conf/timestamp.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = linux123
a1.sources.r1.port = 8888

# 这部分是新增 时间拦截器的 内容
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = timestamp

# 是否保留Event header中已经存在的同名时间戳,缺省值false
a1.sources.r1.interceptors.i1.preserveExisting= false

# 这部分是新增 时间拦截器的 内容
# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 500

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
### --- 启动Agent,启动 telnet 输入信息
~~~     可以看见 event header 中出现了时间戳信息。

[root@linux123 ~]#  $FLUME_HOME/bin/flume-ng agent --name a1 \
--conf-file $FLUME_HOME/conf/timestamp.conf \
-Dflume.root.logger=INFO,console
~~输出参数
INFO sink.LoggerSink: Event: { headers:{timestamp=1630136928094} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 0D             hello world. }
INFO sink.LoggerSink: Event: { headers:{timestamp=1630136929059} body: 31 0D                                           1. }
INFO sink.LoggerSink: Event: { headers:{timestamp=1630136929551} body: 32 0D                                           2. }
INFO sink.LoggerSink: Event: { headers:{timestamp=1630136929952} body: 33 0D                                           3. }
INFO sink.LoggerSink: Event: { headers:{timestamp=1630136930573} body: 34 0D                                           4. }
INFO sink.LoggerSink: Event: { headers:{timestamp=1630136931007} body: 35 0D                                           5. }

[root@linux123 ~]# telnet linux3 8888 
# 输入 hello world

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(20)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示