最近发现一个挺不错的框架mysql-binlog-connector-java,可以实时监控binlog的变化。

首先检查mysql的binlog是否开启,在开启的情况下:

引入依赖

  1. <dependency>
  2. <groupId>com.github.shyiko</groupId>
  3. <artifactId>mysql-binlog-connector-java</artifactId>
  4. <version>0.18.1</version>
  5. </dependency>

 然后使用如下代码可以测试:        

  1. public class App
  2. {
  3. public static void main( String[] args ) throws IOException
  4. {
  5. BinaryLogClient client = new BinaryLogClient("xxx", 3306, "xxx", "xxx");
  6. EventDeserializer eventDeserializer = new EventDeserializer();
  7. eventDeserializer.setCompatibilityMode(
  8. EventDeserializer.CompatibilityMode.DATE_AND_TIME_AS_LONG,
  9. EventDeserializer.CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY
  10. );
  11. client.setEventDeserializer(eventDeserializer);
  12. client.registerEventListener(new EventListener() {
  13.  
  14. @Override
  15. public void onEvent(Event event) {
  16. System.out.println(event);
  17. EventData data = event.getData();
  18.  
  19. if (data instanceof UpdateRowsEventData) {
  20. System.out.println("Update--------------");
  21. System.out.println(data.toString());
  22. } else if (data instanceof WriteRowsEventData) {
  23. System.out.println("Write---------------");
  24. System.out.println(data.toString());
  25. } else if (data instanceof DeleteRowsEventData) {
  26. System.out.println("Delete--------------");
  27. System.out.println(data.toString());
  28. }
  29. }
  30. });
  31. client.connect();
  32. }
  33. }                                                                                                                                                
  34.  
  35. 实际在使用的时候,这个框架提供列名称表名称不太好用,这个时候需要https://github.com/ngocdaothanh/mydit ,这个是一个将mysql同步到mongdb的,其中一些样例代码可以很方便的获取mysql的元数据。

ARTS打卡计划第二周-Tips-mysql-binlog-connector-java的使用的更多相关文章

  1. ARTS打卡计划第二周-Review

    本周review的文章是:https://medium.com/@hakibenita/optimizing-django-admin-paginator-53c4eb6bfca3 改篇文章的题目是: ...

  2. ARTS打卡计划第二周

    Algorithms: https://leetcode-cn.com/problems/3sum/ 算法是先排序,然后按照两个数和两边逼中,考虑去重. Review: https://www.inf ...

  3. ARTS打卡计划第二周-Share-使用java注解对方法计时

    现在有这样一种常见,系统中有一个接口,该接口执行的方法忽快忽慢,因此你需要去统计改方法的执行时间.刚开始你的代码可能如下: long start = System.currentTimeMillis( ...

  4. ARTS打卡计划第二周-Algorithm

    665. 非递减数列  https://leetcode-cn.com/problems/non-decreasing-array/ 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元 ...

  5. ARTS打卡计划第九周

    Algorithms: https://leetcode-cn.com/problems/merge-two-sorted-lists/submissions/ 合并两个链表 Review:  “Pu ...

  6. ARTS打卡计划第一周

    Algorithms: https://leetcode-cn.com/problems/two-sum/ Review: https://www.infoq.cn/article/EafgGJEtq ...

  7. ARTS打卡计划第一周-Share-系统字典模块的设计

    在软件开发的过程,经常有一些类型的字段信息:性别.学历.职级.车辆类别.公司类型.结算类型等.这些字段有2个特征:1是字段可选的类型是有限,2是字段可能会变化,我们把这种字段描述为字段字段.  本篇文 ...

  8. ARTS打卡计划第一周-Tips-ControllerAdvice的使用

    通常在开发具体项目过程中我们可能会面临如下问题: 统一所有的json返回结果 统一处理所有controller中的异常,并且给不同异常不同的返回状态值 统一对返回的接口做数据校验或者加密,防止篡改 在 ...

  9. ARTS打卡计划第一周-Review

    本周分享的文章来自于medium的 Testing Best Practices for Java + Spring Apps 这个文章主要讲的是java测试的一些最佳实践 1.避免函数返回void, ...

随机推荐

  1. 一位工作8年的java软件工程师该如何发展

    从08年到现在已工作8年多了,但是对职业生涯的规划还没有很清晰的定义,可能之前做的工作太杂太广,回想第一家公司从事了6年有得也有失,虽然涉及到开发.设计.管理等岗位,但从技术上总结并没有很擅长的技术, ...

  2. tensorboard OSError:[Errno 22] Invalid argument

    哈哈 问题解决了.感谢大佬 Bill.Z 附上原文链接:https://blog.csdn.net/u013244846/article/details/88380860 解决方法:更改manager ...

  3. Java annotation浅析

    自定义annotation @Documented@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.FIELD,ElementType.M ...

  4. pdf.js的使用

    下载地址:  files.cnblogs.com/zycjwdss/mypdf.zip 把下载后的zip解压,放到web服务器根目录下,打开pdf.html,把这一句取消注释: //window.pd ...

  5. Some elementary algorithms on discrete differential geometry(DDGSpring2016 Demos)

    I studied the on-line course(http://brickisland.net/DDGSpring2016/) by myself, and here are the scre ...

  6. Python——PyQt GUI编程(python programming)

    import sys from math import * from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidg ...

  7. Ubuntu下安装Snap

    介绍 Snap是一个全新的软件包架构,它与其它包管理器的区别在于snap安装的app互相之间是高度隔离的,减少了互相引用. 避免了很多冲突问题. 不过这也导致了其占用的磁盘比较多. 安装 apt in ...

  8. 织梦dede文章列表调用标签的用法和规则

    织梦dede列表标签在任何模板的网站中都可能会使用到,而且我们在仿站的时候也经常要使用到列表标签.这里主机吧就给大家讲一下文章列表以及图片列表.软件列表以及分类信息列表标签的用法,和结合div+css ...

  9. .net core下载文件

    上传的文件是在wwwroot下  通过保存的路径跟文件名称完成下载 public IActionResult DownloadFile() { var filePath = "/Upload ...

  10. Bootstrap关闭子类页面,刷新父类页面

    关闭子类页面,刷新父类页面 function doBack() { var index = parent.layer.getFrameIndex(window.name) //获取窗口索引值 pare ...