一、背景
Windows系统下安装完Flume,flume.conf中source的配置如下:(此source参考Flume官网配置文档中的netcatudp)
# Describe/configure the source
a1.sources.r1.type = netcatudp
a1.sources.r1.bind = 127.0.0.1
a1.sources.r1.port = 6666
在flume安装目录下的bin目录中,shift+右键,运行命令行窗口。输入如下命令运行
flume-ng agent --conf ../conf --conf-file ../conf/example.conf --name a1 -property flume.root.logger=INFO,console
报错:
Caused by: java.lang.NullPointerException: null of map in field headers of org.apache.flume.source.avro.AvroFlumeEvent of array
二、解决
(1)在配置文件中,监听udp时使用com.whitepages.flume.plugins.source.udp.UDPSource这个类,因为官网的netcatudp在source为udp,sinks为avro时会存在bug。
a1.sources = s1
a1.s1.udp.type = com.whitepages.flume.plugins.source.udp.UDPSource
a1.s1.udp.bind = localhost
a1.s1.udp.port = 5515
a1.s1.udp.maxsize = 65536
(2) 生成com.whitepages.flume.plugins.source.udp.UDPSource的jar包
- 项目官网 https://github.com/whitepages/flume-udp-source下载项目zip,然后 eclipse 打开解压后的文件,run as--maven build...-- goals 填入 package -DskipTests。
- 开始执行编译,成功后得到如下三个关键文件:
target/flume-udp-source-1.0.0-SNAPSHOT.jar
target/flume-udp-source-1.0.0-SNAPSHOT-sources.jar
target/flume-udp-source-1.0.0-SNAPSHOT-javadoc.jar
- 将
flume-udp-source-1.0.0-SNAPSHOT.jar
添加到flume的lib目录下即可。
目前在flume的1.5.2和1.6.0和1.9.0 版本上测试没有问题。