-
Notifications
You must be signed in to change notification settings - Fork 1
/
debezium-mysql-realtime-trigger.yaml
87 lines (71 loc) · 2.61 KB
/
debezium-mysql-realtime-trigger.yaml
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
id: debezium-mysql-realtime-trigger
namespace: company.team
tasks:
- id: if
type: io.kestra.plugin.core.flow.If
condition: "{{ trigger.data.metadata.operation == 'DELETE' }}"
then:
- id: log
type: io.kestra.plugin.core.log.Log
message: Employee {{ trigger.data.first_name }} {{ trigger.data.last_name }} has
been deleted
- id: send_alert
type: io.kestra.plugin.notifications.slack.SlackExecution
url: "{{ secret('SLACK_WEBHOOK') }}"
channel: "#general"
customMessage: Employee {{ trigger.data.first_name }} {{ trigger.data.last_name }} has been deleted
triggers:
- id: realtime_trigger
type: io.kestra.plugin.debezium.mysql.RealtimeTrigger
snapshotMode: NEVER
includedTables: test.employees
serverId: "12345"
hostname: localhost
port: "13306"
username: mysql_username
password: mysql_password
extend:
title: Use Debezium MySQL Realtime Trigger to send out alert notification over Slack
description: >-
This flow will:
1. Get
[triggered](https://kestra.io/plugins/plugin-debezium/triggers/io.kestra.plugin.debezium.mysql.realtimetrigger)
every time the change data capture event is produced by the MySQL
2. If there is a DELETE operation on the table, we would log the employee
name that was deleted, and also send out a Slack notificaiton
For creating a MySQL cluster, use the following docker command:
```
docker run -d \
--name mysql \
-v /var/lib/mysql:/var/lib/mysql -p 13306:3306 -e MYSQL_ROOT_PASSWORD=root \
mysql \
mysqld \
--datadir=/var/lib/mysql \
--user=mysql \
--server-id=12345 \
--log-bin=/var/lib/mysql/mysql-bin.log \
--binlog_do_db=test
```
This docker command puts in the necessary configuration to enable the
binlog.
Run the following commands on the MySQL:
```
GRANT REPLICATION SLAVE ON *.* TO 'root'@'%';
# Check if the binlog is enabled
SHOW VARIABLES LIKE 'log_bin';
```
You can now create the `test` database and the `employees` table in MySQL.
```
CREATE DATABASE test;
CREATE TABLE test.employees (id INT, first_name VARCAHR(25), last_name
VARCAHR(25), city VARCAHR(25));
```
When you insert, update or delete data into test.employees table, the flow
will be triggered immediately. Only in case of delete operation, we will log
the message and send out a Slack notification.
tags:
- Realtime Trigger
- Trigger
ee: false
demo: false
meta_description: Use Debezium MySQL Realtime Trigger to send out alert notification over Slack