-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteps
97 lines (63 loc) · 3.26 KB
/
steps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
####### DOCKER #######
# Start the topology as defined in https://debezium.io/documentation/reference/stable/tutorial.html
# Debezium tutorials github repo is here: https://github.com/debezium/debezium-examples/tree/main/tutorial
# Kafka connect env variables description: https://hub.docker.com/r/debezium/connect-base
# Installing a Debezium Connector : https://debezium.io/documentation/reference/stable/install.html
docker-compose -f docker-compose-mysql.yaml up
# Control status of docker containers
docker-compose -f docker-compose-mysql.yaml ps
####### MYSQL #######
# Connect with root
docker-compose -f docker-compose-mysql.yaml exec mysql bash -c 'mysql -u root -pdebezium'
# Show users
SELECT user,host FROM mysql.user;
# Create database
CREATE DATABASE dataops;
# Authorize -debezium- user for -dataops- database
GRANT ALL ON dataops.* TO 'debezium'@'%';
FLUSH PRIVILEGES;
# Exit from root user using ctrl+d
# Log in with -debezium- user (you can see username and password in register-mysql.json)
docker-compose -f docker-compose-mysql.yaml exec mysql bash -c 'mysql -u debezium -pdbz'
# Create table
CREATE TABLE dataops.demo(
customerId int,
customerFName varchar(255),
customerLName varchar(255),
customerCity varchar(255)
);
# Select database
use dataops;
# Show tables
show tables;
# show variables like 'server_id';
####### CONNECTOR #######
# Start MySQL connector! You can register the MySQL connector by sending a POST request to the Kafka Connect API.
# Kafka Connect spawns a new connector instance from the class name specified in the connector.class field.
# MySQL Debezium Connector jars is required in Kafka Connect classpath
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-mysql.json
# To get more information about configuration use this url: https://debezium.io/documentation/reference/stable/connectors/mysql.html#mysql-example-configuration
# CheatSheet for Kafka Connect REST API : https://cheatsheetfactory.geekyhacker.com/kafka/kafka-connect-rest
# Delete MySQL connector
curl -i -X DELETE localhost:8083/connectors/dataops-connector/
# You can take a look options of curl from here: https://gist.github.com/subfuzion/08c5d85437d5d4f00e58
# If you have problem with connector, take a look docker-compose logs
docker-compose -f docker-compose-mysql.yaml logs -f
####### KAFKA #######
# List kafka topics
docker-compose -f docker-compose-mysql.yaml exec kafka /kafka/bin/kafka-topics.sh \
--bootstrap-server kafka:9092 \
--list
# Consume messages from a Debezium topic
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.dataops.demo
####### FINAL #######
# Generate 2-3 batch data to simulate data flow using spark-mysql.py
# Update, Insert and Delete some records using python-mysql.py (or use mysql shell to do this operations)
# Learn about why there are two message when a row is deleted and more: https://debezium.io/documentation/reference/stable/transformations/event-flattening.html
# Examine console outputs via https://jsoncrack.com/editor
# Shut down the cluster
docker-compose -f docker-compose-mysql.yaml down