custom_version/
custom_version.rs1use mysql_replication::{
4 Event, Replication, Result,
5 config::AppConfig,
6 engine::runtime::Runtime,
7 protocol::mysql::{
8 events::{EventParser, MysqlEventParser},
9 version::{FormatDescription, ServerVersion, VersionAdapter},
10 },
11 sink::{JsonLinesSink, TransactionSink},
12};
13use std::{io::BufWriter, path::Path, sync::Arc};
14struct CustomMysql;
15impl VersionAdapter for CustomMysql {
16 fn name(&self) -> &str {
17 "custom-mysql"
18 }
19 fn supports(&self, version: &ServerVersion) -> bool {
20 version.major == 9
21 && version.minor == 1
22 && !version.raw.to_ascii_lowercase().contains("mariadb")
23 }
24 fn status_query(&self) -> &str {
25 "SHOW BINARY LOG STATUS"
26 }
27 fn create_event_parser(&self, format: &FormatDescription<'_>) -> Result<Box<dyn EventParser>> {
28 Ok(Box::new(MysqlEventParser::from_format(format)?))
33 }
34 }
38fn main() -> Result<()> {
39 let Some(path) = std::env::args().nth(1) else {
40 eprintln!("usage: cargo run -p mysql-replication --example custom_version -- CONFIG.toml");
41 return Ok(());
42 };
43 let mut runtime = Runtime::default();
44 runtime.versions.register(Arc::new(CustomMysql))?;
45 let mut replication = Replication::with_runtime(AppConfig::read(Path::new(&path))?, runtime)?;
46 let output = JsonLinesSink::new(BufWriter::new(std::io::stdout()));
47 replication.add_handle(move |event: Event<'_>| {
48 output.commit(event.source_id, event.checkpoint, event.changes)
49 });
50 replication.run()
51}