Skip to content

Commit cad0906

Browse files
committed
Debezium: Implement suggestions by CodeRabbit
1 parent 540f5d8 commit cad0906

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

docs/integrate/debezium/tutorial.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We know we can address several of these points by using a system like CrateDB. C
2020

2121
If only we could replicate data from our operational database to CrateDB without having to write custom code… it turns out we can.
2222

23-
Enter Debezium, [Debezium ](https://debezium.io/)is a standard open-source system, built on top of Kafka, which allows to capture changes on a source database system and replicate them on another system without having to write custom scripts.
23+
Enter Debezium. [Debezium](https://debezium.io/) is a standard open-source system, built on top of Kafka, which allows to capture changes on a source database system and replicate them on another system without having to write custom scripts.
2424

2525
In this post I want to show an example replicating changes on a table from MSSQL to CrateDB.
2626

@@ -39,10 +39,10 @@ CREATE DATABASE erp;
3939
GO
4040
USE erp;
4141
CREATE TABLE dbo.tbltest (
42-
id INT PRIMARY KEY IDENTITY,
43-
createdon DATETIME DEFAULT getdate(),
44-
srcsystem NVARCHAR(max)
45-
);
42+
id INT PRIMARY KEY IDENTITY,
43+
createdon DATETIME DEFAULT getdate(),
44+
srcsystem NVARCHAR(max)
45+
);
4646
```
4747
Let’s now create an account for Debezium to use to pull the changes:
4848

@@ -60,15 +60,15 @@ And let’s enable change data capture on our example table:
6060
EXEC sys.sp_cdc_enable_db;
6161
ALTER DATABASE erp ADD FILEGROUP cdcfg;
6262
ALTER DATABASE erp ADD FILE (
63-
NAME= erp_cdc_file1,
64-
FILENAME='/var/opt/mssql/data/erp_cdc_file1.ndf'
65-
) TO FILEGROUP cdcfg;
63+
NAME= erp_cdc_file1,
64+
FILENAME='/var/opt/mssql/data/erp_cdc_file1.ndf'
65+
) TO FILEGROUP cdcfg;
6666
EXEC sys.sp_cdc_enable_table
67-
@source_schema='dbo',
68-
@source_name='tbltest',
69-
@role_name='debeziumrole',
70-
@filegroup_name='cdcfg',
71-
@supports_net_changes=0;
67+
@source_schema='dbo',
68+
@source_name='tbltest',
69+
@role_name='debeziumrole',
70+
@filegroup_name='cdcfg',
71+
@supports_net_changes=0;
7272
```
7373

7474
## Setup on the CrateDB side
@@ -98,10 +98,10 @@ And let’s create the structure of the table that will receive the data:
9898

9999
```sql
100100
CREATE TABLE dbo.tbltest (
101-
id INT PRIMARY KEY /* we need the PK definition to match the source table so that this can be used to lookup records when they need to be updated */
102-
,createdon TIMESTAMP /* CrateDB supports defaults -of course- but because the source table already has a default value we do not need that here */
103-
,srcsystem TEXT
104-
);
101+
id INT PRIMARY KEY, /* we need the PK definition to match the source table so that this can be used to lookup records when they need to be updated */
102+
createdon TIMESTAMP, /* CrateDB supports defaults -of course- but because the source table already has a default value we do not need that here */
103+
srcsystem TEXT
104+
);
105105
```
106106

107107
## Zookeeper and Kafka
@@ -141,7 +141,7 @@ mkdir confluentinc-kafka-connect-jdbc-10.6.3
141141
cd confluentinc-kafka-connect-jdbc-10.6.3
142142
unzip -j ../confluentinc-kafka-connect-jdbc-10.6.3.zip
143143
cd ..
144-
cat > Dockerfile <<EOF
144+
cat > Dockerfile <<EOF
145145
FROM debezium/connect
146146
USER root:root
147147
COPY ./confluentinc-kafka-connect-jdbc-10.6.3/ /kafka/connect/
@@ -155,15 +155,15 @@ Let’s now start this custom image:
155155

156156
```bash
157157
sudo docker run -it --rm --name connect -p 8083:8083 \
158-
-e GROUP_ID=1 \
159-
-e CONFIG_STORAGE_TOPIC=my_connect_configs \
160-
-e OFFSET_STORAGE_TOPIC=my_connect_offsets \
161-
--add-host host.docker.internal:host-gateway \
162-
--add-host $(hostname):host-gateway \
163-
-e BOOTSTRAP_SERVERS=host.docker.internal:9092 \
164-
-e KEY_CONVERTER=org.apache.kafka.connect.json.JsonConverter \
165-
-e VALUE_CONVERTER=org.apache.kafka.connect.json.JsonConverter \
166-
cratedb-connect-debezium
158+
-e GROUP_ID=1 \
159+
-e CONFIG_STORAGE_TOPIC=my_connect_configs \
160+
-e OFFSET_STORAGE_TOPIC=my_connect_offsets \
161+
--add-host host.docker.internal:host-gateway \
162+
--add-host $(hostname):host-gateway \
163+
-e BOOTSTRAP_SERVERS=host.docker.internal:9092 \
164+
-e KEY_CONVERTER=org.apache.kafka.connect.json.JsonConverter \
165+
-e VALUE_CONVERTER=org.apache.kafka.connect.json.JsonConverter \
166+
cratedb-connect-debezium
167167
```
168168

169169
This assumes Kafka is running locally on the same server, you will need to adjust `BOOTSTRAP_SERVERS` if that is not the case.
@@ -174,27 +174,27 @@ Let’s create a `connector.json` file as follows:
174174

175175
```json
176176
{
177-
"name": "mssql-source-tbltest",
178-
"config": {
179-
"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector",
180-
"tasks.max": "1",
181-
182-
"database.history.kafka.bootstrap.servers": "host.docker.internal:9092",
183-
"schema.history.internal.kafka.bootstrap.servers": "host.docker.internal:9092",
184-
"topic.prefix": "cratedbdemo",
185-
"database.encrypt": "false",
186-
187-
"database.hostname": "host.docker.internal",
188-
"database.port": "1433",
189-
"database.user": "debeziumlogin",
190-
"database.password": "<enterStrongPasswordHere>",
191-
"database.server.name": "mssql-server",
192-
193-
"database.names": "erp",
194-
"table.whitelist": "dbo.tbltest",
195-
"database.history.kafka.topic": "schema-changes.mssql-server.tbltest",
196-
"schema.history.internal.kafka.topic": "schema-changes.inventory.mssql-server.tbltest"
197-
}
177+
"name": "mssql-source-tbltest",
178+
"config": {
179+
"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector",
180+
"tasks.max": "1",
181+
182+
"database.history.kafka.bootstrap.servers": "host.docker.internal:9092",
183+
"schema.history.internal.kafka.bootstrap.servers": "host.docker.internal:9092",
184+
"topic.prefix": "cratedbdemo",
185+
"database.encrypt": "false",
186+
187+
"database.hostname": "host.docker.internal",
188+
"database.port": "1433",
189+
"database.user": "debeziumlogin",
190+
"database.password": "<enterStrongPasswordHere>",
191+
"database.server.name": "mssql-server",
192+
193+
"database.names": "erp",
194+
"table.whitelist": "dbo.tbltest",
195+
"database.history.kafka.topic": "schema-changes.mssql-server.tbltest",
196+
"schema.history.internal.kafka.topic": "schema-changes.inventory.mssql-server.tbltest"
197+
}
198198
}
199199
```
200200

@@ -212,27 +212,27 @@ Let’s create a `destination-connector.json` file as follows:
212212

213213
```json
214214
{
215-
"name": "cratedb-sink-tbltest",
216-
"config": {
217-
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
218-
"tasks.max": "1",
219-
220-
"connection.url": "jdbc:postgresql://host.docker.internal:5432/",
221-
"connection.user": "debezium",
222-
"connection.password": "debeziumpwdincratedb123",
223-
224-
"topics": "cratedbdemo.erp.dbo.tbltest",
225-
"table.name.format": "dbo.tbltest",
226-
"auto.create": "false",
227-
"auto.evolve": "false",
228-
229-
"insert.mode": "upsert",
230-
"pk.fields": "id",
231-
"pk.mode": "record_value",
232-
233-
"transforms": "unwrap",
234-
"transforms.unwrap.type": "io.debezium.transforms.ExtractNewRecordState"
235-
}
215+
"name": "cratedb-sink-tbltest",
216+
"config": {
217+
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
218+
"tasks.max": "1",
219+
220+
"connection.url": "jdbc:postgresql://host.docker.internal:5432/",
221+
"connection.user": "debezium",
222+
"connection.password": "debeziumpwdincratedb123",
223+
224+
"topics": "cratedbdemo.erp.dbo.tbltest",
225+
"table.name.format": "dbo.tbltest",
226+
"auto.create": "false",
227+
"auto.evolve": "false",
228+
229+
"insert.mode": "upsert",
230+
"pk.fields": "id",
231+
"pk.mode": "record_value",
232+
233+
"transforms": "unwrap",
234+
"transforms.unwrap.type": "io.debezium.transforms.ExtractNewRecordState"
235+
}
236236
}
237237
```
238238

@@ -270,7 +270,7 @@ SET srcsystem = 'Updated successfully'
270270
WHERE id = 1
271271
```
272272

273-
![image|690x191](https://us1.discourse-cdn.com/flex020/uploads/crate/original/1X/4476976451e1f943112082a7d1e0cd36524740a1.png)
273+
![CrateDB query result showing updated record](https://us1.discourse-cdn.com/flex020/uploads/crate/original/1X/4476976451e1f943112082a7d1e0cd36524740a1.png)
274274

275275
## Conclusion
276276

0 commit comments

Comments
 (0)