首页 文章 精选 留言 我的

精选列表

搜索[Java],共10000篇文章
优秀的个人博客,低调大师

binlog4j 1.3.0 发布,Java 轻量级 binlog 客户端

Binlog4j 轻量级 Mysql Binlog 客户端, 提供宕机续读, 高可用集群等特性 项目特性 集群模式, 通过集群部署的方式,保证服务高可用。 宕机续读, 避免宕机期间造成数据丢失。 数据转换, 基于泛型封装 binlog Event 的序列化数据。 兼容 传统项目 与 Spring Boot / Cloud 项目。 兼容 Spring Boot 2.x 与 Spring Boot 3.x 版本。 更新日志(1.3.0) [新增] LocalDate 类型字段兼容。[新增] LocalDateTime 类型字段兼容。[新增] BinlogEvent 类 timestamp 字段,发生时间。[新增] BinlogClient 类 registerEventHandler(IBinlogEventHandler eventHandler) 方法 下载安装 <dependency> <groupId>com.gitee.Jmysy</groupId> <artifactId>binlog4j-core</artifactId> <version>latest.version</version> </dependency> 或 implementation group: 'com.gitee.Jmysy', name: 'binlog4j-core', version: 'latest.version' 简单使用 通过 BinlogClient 创建 binlog 客户端, IBinlogEventHandler 用于接受 binlog 事件通知, 该接口允许使用泛型, 数据将遵循驼峰规则进行封装。 public class BootStrap { public static void main(String[] args) { BinlogClientConfig clientConfig = new BinlogClientConfig(); clientConfig.setHost("127.0.0.1"); clientConfig.setPort(3306); clientConfig.setUsername("root"); clientConfig.setPassword("taoren@123"); clientConfig.setServerId(1990); IBinlogClient binlogClient = new BinlogClient(clientConfig); binlogClient.registerEventHandler("database", "table", new IBinlogEventHandler() { @Override public void onInsert(BinlogEvent event) { System.out.println("插入数据:{}", event.getData()); } @Override public void onUpdate(BinlogEvent event) { System.out.println("修改数据:{}", event.getData()); } @Override public void onDelete(BinlogEvent event) { System.out.println("删除数据:{}", event.getData()); } }); binlogClient.connect(); } } 高级特性 通过 Persistence 配置为 true 启用宕机续读功能, Binlog4j 会将 binlog 的 filename 与 position 记录到 redis, 所以同时你需要设置 Redis 配置。 public class BootStrap { public static void main(String[] args) { RedisConfig redisConfig = new RedisConfig(); redisConfig.setHost("127.0.0.1"); redisConfig.setPort(6379); redisConfig.setPassword("taoren@123"); BinlogClientConfig clientConfig = new BinlogClientConfig(); clientConfig.setHost("127.0.0.1"); clientConfig.setPort(3306); clientConfig.setUsername("root"); clientConfig.setPassword("taoren@123"); clientConfig.setServerId(1990); // Client 编号 clientConfig.setRedisConfig(redisConfig); // Redis 配置 clientConfig.setPersistence(true); // 启用持久化 (宕机重启后, 从上次读取的位置开始) clientConfig.setMode(BinlogClientMode.cluster); // 高可用集群 BinlogClient binlogClient = new BinlogClient(clientConfig); binlogClient.registerEventHandler("database", "table", new IBinlogEventHandler<User>() { @Override public void onInsert(BinlogEvent<User> event) { System.out.println("插入数据:{}", event.getData()); } @Override public void onUpdate(BinlogEvent<User> event) { System.out.println("修改数据:{}", event.getData()); } @Override public void onDelete(BinlogEvent<User> event) { System.out.println("删除数据:{}", event.getData()); } }); binlogClient.connect(); } } Spring Boot Starter <dependency> <groupId>com.gitee.Jmysy</groupId> <artifactId>binlog4j-spring-boot-starter</artifactId> <version>latest.version</version> </dependency> 或 implementation group: 'com.gitee.Jmysy', name: 'binlog4j-spring-boot-starter', version: 'latest.version' 首先, 在 application.yml 中填写 BinlogClient 配置 spring: binlog4j: redis-config: host: 127.0.0.1 port: 6379 password: taoren@123 client-configs: master: username: root password: taoren@123 host: 127.0.0.1 port: 3306 serverId: 1990 单表监听 使用 @BinlogSubscriber 注解, 指定 IBinlogEventHandler 需要注册到哪个客户端, 并且指定监听的 database 与 table。 @BinlogSubscriber(clientName = "master", database = "pear-admin", table ="sys_user") public class UserEventHandler implements IBinlogEventHandler<User> { @Override public void onInsert(BinlogEvent<User> event) { System.out.println("插入数据:" + event.getData()); } @Override public void onUpdate(BinlogEvent<User> event) { System.out.println("修改数据:" + event.getData()); } @Override public void onDelete(BinlogEvent<User> event) { System.out.println("删除数据:" + event.getData()); } } 多表监听 @BinlogSubscriber 注解 database 与 table 属性支持 Pattern 匹配, IBinlogEventHandler 在不指定泛型的情况下, event.getData() 为 Map<String, Object> 类型, 用于兼容不同表的数据结构。 @BinlogSubscriber(clientName = "master", database = ".*", table ="sys.*") public class UserEventHandler implements IBinlogEventHandler { @Override public void onInsert(BinlogEvent event) { System.out.println("数据库:" + event.getDatabase()); System.out.println("数据表:" + event.getTable()); System.out.println("新数据:" + event.getData()); } @Override public void onUpdate(BinlogEvent event) { System.out.println("数据库:" + event.getDatabase()); System.out.println("数据表:" + event.getTable()); System.out.println("原数据:" + event.getOriginalData()); System.out.println("新数据:" + event.getData()); } @Override public void onDelete(BinlogEvent event) { System.out.println("数据库:" + event.getDatabase()); System.out.println("数据表:" + event.getTable()); System.out.println("新数据:" + event.getData()); } } 监听 master 数据源所有数据库中所有表的数据变化【最灵活】 @BinlogSubscriber(clientName = "master") 监听 master 数据源 pear-admin 数据库中所有表的数据变化 @BinlogSubscriber(clientName = "master", database="pear-admin") 监听 master 数据源 pear-admin 数据库中 user 表的数据变化 @BinlogSubscriber(clientName = "master", database="pear-admin", table="user") 监听 master 数据源所有数据库中 user 表的数据变化 @BinlogSubscriber(clientName = "master", table="user") 监听 master 数据源所有数据库中以 user 开头的表的数据变化 @BinlogSubscriber(clientName = "master", table="user.*")

优秀的个人博客,低调大师

binlog4j 1.1.1 发布,Java 轻量级 binlog 客户端

Binlog4j 轻量级 Mysql Binlog 客户端, 提供宕机续读, 高可用集群等特性 项目特性 集群模式, 通过集群部署的方式,保证服务高可用。 宕机续读, 避免宕机期间造成数据丢失。 数据转换, 基于泛型封装 binlog Event 的序列化数据。 兼容 传统项目 与 Spring Boot / Cloud 项目。 兼容 Spring Boot 2.x 与 Spring Boot 3.x 版本。 更新日志(1.1.1) [移除] fast-json 依赖,使用 gson 代替。[修复] IBinlogEventHandler 接口 data 与 originalData 相反的问题。 下载安装 <dependency> <groupId>com.gitee.Jmysy</groupId> <artifactId>binlog4j-core</artifactId> <version>latest.version</version> </dependency> 或 implementation group: 'com.gitee.Jmysy', name: 'binlog4j-core', version: 'latest.version' 简单使用 通过 BinlogClient 创建 binlog 客户端, IBinlogEventHandler 用于接受 binlog 事件通知, 该接口允许使用泛型, 数据将遵循驼峰规则进行封装。 public class BootStrap { public static void main(String[] args) { BinlogClientConfig clientConfig = new BinlogClientConfig(); clientConfig.setHost("127.0.0.1"); clientConfig.setPort(3306); clientConfig.setUsername("root"); clientConfig.setPassword("taoren@123"); clientConfig.setServerId(1990); IBinlogClient binlogClient = new BinlogClient(clientConfig); binlogClient.registerEventHandler("database", "table", new IBinlogEventHandler() { @Override public void onInsert(BinlogEvent event) { System.out.println("插入数据:{}", event.getData()); } @Override public void onUpdate(BinlogEvent event) { System.out.println("修改数据:{}", event.getData()); } @Override public void onDelete(BinlogEvent event) { System.out.println("删除数据:{}", event.getData()); } }); binlogClient.connect(); } } 高级特性 通过 Persistence 配置为 true 启用宕机续读功能, Binlog4j 会将 binlog 的 filename 与 position 记录到 redis, 所以同时你需要设置 Redis 配置。 public class BootStrap { public static void main(String[] args) { RedisConfig redisConfig = new RedisConfig(); redisConfig.setHost("127.0.0.1"); redisConfig.setPort(6379); redisConfig.setPassword("taoren@123"); BinlogClientConfig clientConfig = new BinlogClientConfig(); clientConfig.setHost("127.0.0.1"); clientConfig.setPort(3306); clientConfig.setUsername("root"); clientConfig.setPassword("taoren@123"); clientConfig.setServerId(1990); // Client 编号 clientConfig.setRedisConfig(redisConfig); // Redis 配置 clientConfig.setPersistence(true); // 启用持久化 (宕机重启后, 从上次读取的位置开始) clientConfig.setMode(BinlogClientMode.cluster); // 高可用集群 BinlogClient binlogClient = new BinlogClient(clientConfig); binlogClient.registerEventHandler("database", "table", new IBinlogEventHandler<User>() { @Override public void onInsert(BinlogEvent<User> event) { System.out.println("插入数据:{}", event.getData()); } @Override public void onUpdate(BinlogEvent<User> event) { System.out.println("修改数据:{}", event.getData()); } @Override public void onDelete(BinlogEvent<User> event) { System.out.println("删除数据:{}", event.getData()); } }); binlogClient.connect(); } } Spring Boot Starter <dependency> <groupId>com.gitee.Jmysy</groupId> <artifactId>binlog4j-spring-boot-starter</artifactId> <version>latest.version</version> </dependency> 或 implementation group: 'com.gitee.Jmysy', name: 'binlog4j-spring-boot-starter', version: 'latest.version' 首先, 在 application.yml 中填写 BinlogClient 配置 spring: binlog4j: redis-config: host: 127.0.0.1 port: 6379 password: taoren@123 client-configs: master: username: root password: taoren@123 host: 127.0.0.1 port: 3306 serverId: 1990 使用 @BinlogSubscriber 注解, 指定 IBinlogEventHandler 需要注册到哪个客户端, 并且指定监听的 database 与 table。 @BinlogSubscriber(clientName = "master", database = "pear-admin", table ="sys_user") public class UserEventHandler implements IBinlogEventHandler<User> { @Override public void onInsert(BinlogEvent<User> event) { System.out.println("插入数据:" + event.getData()); } @Override public void onUpdate(BinlogEvent<User> event) { System.out.println("修改数据:" + event.getData()); } @Override public void onDelete(BinlogEvent<User> event) { System.out.println("删除数据:" + event.getData()); } } 多表监听, database 与 table 使用 Pattern 匹配, 泛型不应该再被使用, data 默认为 Map<String, Object> 类型 @BinlogSubscriber(clientName = "master", database = ".*", table ="sys.*") public class UserEventHandler implements IBinlogEventHandler<User> { @Override public void onInsert(BinlogEvent<User> event) { System.out.println("数据库:" + event.getDatabase()); System.out.println("数据表:" + event.getTable()); System.out.println("新数据:" + event.getData()); } @Override public void onUpdate(BinlogEvent<User> event) { System.out.println("数据库:" + event.getDatabase()); System.out.println("数据表:" + event.getTable()); System.out.println("原数据:" + event.getOriginalData()); System.out.println("新数据:" + event.getData()); } @Override public void onDelete(BinlogEvent<User> event) { System.out.println("数据库:" + event.getDatabase()); System.out.println("数据表:" + event.getTable()); System.out.println("新数据:" + event.getData()); } }

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册