Based on JackShadow/go-binlog-example
See full docs here
- MySQL
- MySQL
- PostgreSQL
- Yandex ClickHouse
- HP Vertica
See quick start tutorial here
- Copy
src/.env.disttosrc/.envand set credentials. - Configure your my MySQL master as
examples/master/mysql.conf. Don't forget to setbinlog_do_db=<master_db_name>and restart MySQL service. - Create databases and tables as
examples/sql/. - Start Docker as
make start-dev - Run as
cd srcandgo run main.go listenin docker container. - Copy
examples/configs/user.jsonandexamples/configs/post.jsontosrc/system/configs - Execute
cd srcandgo run main.go load
- Use
create-model <table>to create json config for your table. - Create table on slave.
- Set
<table>toTABLEparam insrc/.env - Use
build-slaveto copy table data from master and set start position of log for table listener.
- Create
plugins/user/<plugin_name>/handler.golikeplugins/system/set_value/handler.go - Execute
go build -buildmode=plugin -o plugins/user/<plugin_name>/handler.so plugins/user/<plugin_name>/handler.go - Add to field description in your
src/system/configs/<model>.json
"beforeSave": {
"handler": "user/<plugin_name>",
"params": [
"***"
]
}
- If you want to set custom field value use
system/set_valueashandlerparam. Don't forget to setparams: ["<value>"]
set-position <table> <binlog_name> <binlog_position>set start position of log for table listenerloadstart loader for replication testing (for default tables user and post)create-model <table>create model json-file by master table structurebuild-slavecreate master table dump, restore this dump in slave, set start position of log for table listenerdestroy-slavetruncate table, set empty position of log for table listener
-
Prod mode: build app and execute listener.
Use
make build-prodandmake start-prodto start andmake stop-prodto stop. -
Dev mode: provides the opportunity for manual start and debug.
Use
make start-devto start andmake stop-devto stop.