Flume整合mysql碰到的自定义source表名问题
来源:互联网 发布:电脑培训软件机构咨询 编辑:程序博客网 时间:2024/05/20 00:51
之前项目中碰到了一些关于flume采集的问题,把一些解决方法介绍一下,用于针对不同需求的采集需求。我所碰到的问题是flume采集mysql中数据的时候,表名不唯一的问题,我们常用flume-sql-source.jar的时候,在配置文件里面会加上 a3.sources.src-1.table=表名 ,这个表名不能更改,比如说每天采集的表名不是一样的,那每天都需要改这里的配置表名,而常用的%y%m%d这种配置是适配不出来每天的日期,因为这个配置会在flume-sql-source中按字符串读进去,并不能适配像shell脚本的匹配日期那样,碰到这种问题,无非是从flume-sql-source入手,更改它读取table字段的方式,制作一个满足特定需求的依赖即可,不用自己再写一个自定义source那么麻烦。
(1)首先查看一下flume-sql-source.jar中的内容,找到读取配置文件并赋值的类的位置,这里我找到位置在org.keedio.flume.source.SQLSourceHelper类中构造方法里面
public SQLSourceHelper(Context context, String sourceName) { this.statusFilePath = context.getString("status.file.path", "/var/lib/flume"); this.statusFileName = context.getString("status.file.name"); this.connectionURL = context.getString("connection.url"); this.table=context.getString("table"); //------这个位置table的表名 this.columnsToSelect = context.getString("columns.to.select", "*"); this.runQueryDelay = context.getInteger("run.query.delay", Integer.valueOf(10000)).intValue(); this.user = context.getString("user"); this.password = context.getString("password"); this.directory = new File(this.statusFilePath); this.customQuery = context.getString("custom.query"); this.batchSize = context.getInteger("batch.size", Integer.valueOf(100)).intValue(); this.maxRows = context.getInteger("max.rows", Integer.valueOf(10000)).intValue(); this.hibernateDialect = context.getString("hibernate.dialect"); this.hibernateDriver = context.getString("hibernate.connection.driver_class"); this.sourceName = sourceName; this.statusColumn = context.getString("status.column"); this.startFrom = context.getString("start.from"); this.checkMandatoryProperties(); if(!this.isStatusDirectoryCreated()) { this.createDirectory(); } this.file = new File(this.statusFilePath + "/" + this.statusFileName); this.currentIndex = this.getStatusFileIndex(context.getInteger(this.startFrom, Integer.valueOf(0)).intValue()); this.query = this.buildQuery(); }
(2)如果需要改写jar包的话,还要反编译软件太麻烦,这里直接新建一个project,注意:新建的包名要与org.keedio.flume.source一致,然后将SQLSourceHelper类中的内容拷贝到新建的class中,注意class名也要一致,然后在pom里面配置一些依赖,没有错误之后,注释掉this.table=context.getString(“table”);然后加上一些更改:比如说我的需求的表名始终是n_加上当日日期,那只需要将this.table=context.getString(“table”)更改为如下:
SimpleDateFormat format = new SimpleDateFormat("yyMMdd");String time = format.format(date);this.table = "n_" + time;
然后没有报错之后,在进行编译,把编译好的SQLSourceHelper.class替换原来jar包中的SQLSourceHelper.class,保存上传到flume的lib目录,执行
bin/flume-ng agent -n a4 -c conf/ -f conf/a4.conf -Dflume.root.logger=INFO,console
之后就成功了,连接自己本地的mysql新建一个表名为n_170709做个测试,发现
测试成功,在hdfs上flume目录下就可看到采集的内容:
这里由于是在我自己的集群上,速度比较慢,我设置了每隔60s形成一个文件,所以采集出来是多个文件的格式。
阅读全文
0 0
- Flume整合mysql碰到的自定义source表名问题
- flume自定义sink source
- flume自定义source
- flume自定义source
- 自定义flume-source
- 编译Android Source时碰到的问题
- Apache+Tomcat整合后碰到的问题
- 整合百度推送碰到的问题
- mysql碰到的一些问题
- 安装MYSQL碰到的问题
- flume常用source问题总结
- flume常用source问题总结
- 自定义UICollectionViewCell 以及碰到的问题
- flume学习(八):自定义source
- flume学习(七):自定义source
- flume 自定义source,sink,channel,拦截器
- myeclipse中碰到类名太长的问题
- mysql启动碰到过的问题
- Service使用总结
- Go编程基础—并发(concurrency)
- python opencv 资料收集
- Device eth0 does not seem to be present,delaying initialization的解决办法
- CRC检验解析
- Flume整合mysql碰到的自定义source表名问题
- stm32菜鸟自学代码
- 开机第二屏幕分辨率改变的几种解决方法
- java 中 return 语句总结
- 如何阅读一篇论文
- 关于STM32使用RTC时复位后程序死在 RTC
- hdu2048神、上帝以及老天爷(排错问题)
- 数据压缩原理 实验六 MPEG音频编码
- 欢迎使用CSDN-markdown编辑器