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.dist
tosrc/.env
and 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 src
andgo run main.go listen
in docker container. - Copy
examples/configs/user.json
andexamples/configs/post.json
tosrc/system/configs
- Execute
cd src
andgo run main.go load
- Use
create-model <table>
to create json config for your table. - Create table on slave.
- Set
<table>
toTABLE
param insrc/.env
- Use
build-slave
to copy table data from master and set start position of log for table listener.
- Create
plugins/user/<plugin_name>/handler.go
likeplugins/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_value
ashandler
param. Don't forget to setparams: ["<value>"]
set-position <table> <binlog_name> <binlog_position>
set start position of log for table listenerload
start loader for replication testing (for default tables user and post)create-model <table>
create model json-file by master table structurebuild-slave
create master table dump, restore this dump in slave, set start position of log for table listenerdestroy-slave
truncate table, set empty position of log for table listener
-
Prod mode: build app and execute listener.
Use
make build-prod
andmake start-prod
to start andmake stop-prod
to stop. -
Dev mode: provides the opportunity for manual start and debug.
Use
make start-dev
to start andmake stop-dev
to stop.