Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stonyshi/mysql--channel
mysql binlog-event protocol
https://github.com/stonyshi/mysql--channel
Last synced: about 2 months ago
JSON representation
mysql binlog-event protocol
- Host: GitHub
- URL: https://github.com/stonyshi/mysql--channel
- Owner: StonyShi
- Created: 2018-10-26T06:45:43.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-23T06:56:12.000Z (almost 2 years ago)
- Last Synced: 2024-04-16T18:13:26.861Z (9 months ago)
- Language: Java
- Size: 81.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mysql 协议 binlog 解析
## SlaveConnector 远程连接 binlog event接收
```
SlaveConnector connector = new SlaveConnector(host, port, username, password);
connector.setServerId(5);connector.addFilter(new EventFilter(new EventType[]{UPDATE_ROWS_EVENT, DELETE_ROWS_EVENT, WRITE_ROWS_EVENT}));
connector.addFilter(new DatabaseFilter(new String[]{"test"}));connector.registerListener(event -> {
try {
System.out.println(event);
} catch (Exception e) {
e.printStackTrace();
}
});
connector.registerListener(new EventListener() {
@Override
public void onEvent(BinlogEvent event) {
try {
System.out.println(JsonUtil.toString(event));
System.out.println();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
});
connector.startAndAwait();
connector.shutdown();
```## binlog 文件解析
```
FileConnector connector = new FileConnector("/Users/stony/Downloads/my-bin.000032");connector.setChecksumType(ChecksumType.CRC32);
//自定义过滤
connector.addFilter(new Filter() {
@Override
public boolean test(BinlogEvent event) {
BinlogEvent.Event myEvent = event.getEvent();
if ((myEvent instanceof RowsEvent) || (myEvent instanceof TableMapEvent)) {
String dbName;
String tName;
if (myEvent instanceof RowsEvent) {
dbName = ((RowsEvent) myEvent).getSchema();
tName = ((RowsEvent) myEvent).getTableName();
} else {
dbName = ((TableMapEvent) myEvent).getSchema();
tName = ((TableMapEvent) myEvent).getTable();
}
if (dbName != null && "employees".equals(dbName)) {
if (tName != null && "employees".equals(tName)) {
return true;
}
}
}
return false;
}
});
connector.registerListener(event -> {
try {
System.out.println(event);
} catch (Exception e) {
e.printStackTrace();
}
});
connector.startAndAwait();
connector.shutdown();
```# mysql 协议文档
https://segmentfault.com/a/1190000038549577