- Microservice-CDC-Mysql Tutorial using Debezium Source and Confluent Sink Connector
docker-compose -f docker-compose-mysql.yaml up -d
localhost:8083/connector-plugins
localhost:8083/connectors/
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-mysql.json
docker-compose -f docker-compose-mysql.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
--bootstrap-server kafka:9092 \
--from-beginning \
--property print.key=true \
--topic dbserver1.inventory.customers
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-mysql-sink.json
Register multiple sink connector for different tables, if primary key or the configuration differs
http://localhost:8083/connectors/jdbc-sink-connector/status
curl -X DELETE localhost:8083/connectors/jdbc-sink-connector
curl -X POST localhost:8083/connectors/jdbc-sink-connector/restart
docker-compose -f docker-compose-mysql.yaml exec mysql bash -c 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD inventory'
docker-compose -f docker-compose-mysql.yaml exec mysqldestination bash -c 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD inventory'
select * from customers;
update customers set first_name='dip';
insert into customers(id,first_name,last_name,email) values(1005,'1','1','1');
select * from kafka_customers;
delete from customers where id=1005;
Add column in source : Column will only be added if any new insert sql statement is found with the new column
ALTER TABLE customers ADD phone varchar(40) NULL AFTER email;
Rename column name in source : Column will only be added if any new insert sql statement is found with the new column,but old data in not available in new column. So only rename columns if data are not added in old field
ALTER TABLE customers CHANGE COLUMN phone mobile varchar(20) NULL;
ALTER TABLE customers DROP COLUMN mobile;
Index/Unique index/Auto increment column/Foreign Keys is not added in destination, but due to it no adverse effect is found yet
SHOW VARIABLES LIKE 'log_bin';
Add multiple comma seperated tables name that needs to be replicated should be placed in topics key of sink connector configuration
"topics": "customers,addresses,products"
Eg: For customers table, kafka_customers will be created in the destination.
"table.name.format":"kafka_${topic}",
The maximum number of tasks that should be created for this connector. The connector may create fewer tasks if it cannot achieve this level of parallelism. Eg: "tasks.max" : 3
SELECT @@server_id
Refer debezium config for more
docker-compose -f docker-compose-mysql.yaml down
Thanks to the below contributors
- Microservices - Database per service architecture
- Use CQRS to overcome Database per service pitfalls
- Inspired by Eventuate Tram
- Debezium Mysql Source Connector
- Confluent JDBC Sink Connector configuration
- Manage Confluent Kafka connector
- Inplace of Debezium, Confluent JDBC Source Connector configuration can also be used.
- Other Debezium source connector examples