Skip to content

Commit d5ba85e

Browse files
authored
Merge pull request #9 from AlessandroLollo/update-demo-for-debezium-2.7
Updated code and README to run with Debezium 2.7
2 parents ba15df7 + adda30d commit d5ba85e

21 files changed

+166
-101
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,7 @@ ASALocalRun/
332332
# Additional files
333333
**.env
334334
__blobstorage__/
335-
__azurite_db_*
335+
__azurite_db_*
336+
337+
# SQL Server Debezium connector config (generated)
338+
sqlserver-connector-config.json

README.md

+66-18
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,46 @@ The script `01-enable-cdc.sql` enable Change Data Capture on the aforementioned
7070
All data gathered by Change Data Capture will be send to Event Hubs, so create an Azure Event Hubs in your Azure Subscription. Using the [Azure Cloud Shell](https://shell.azure.com/) Bash:
7171

7272
```bash
73-
# create group
74-
az group create -n debezium -l eastus
73+
# Set vars
74+
RESOURCE_GROUP=debezium
75+
LOCATION=eastus
76+
EVENTHUB_NAMESPACE=debezium
77+
EVENTHUB_SCHEMA_HISTORY=schemahistory
7578

76-
# create eventhuvbs with kafka enabled
77-
az eventhubs namespace create -n debezium -g debezium -l eastus --enable-kafka
79+
# create group
80+
az group create \
81+
--name $RESOURCE_GROUP \
82+
--location $LOCATION
83+
84+
# create eventhub namespace with kafka enabled
85+
az eventhubs namespace create \
86+
--name $EVENTHUB_NAMESPACE \
87+
--resource-group $RESOURCE_GROUP \
88+
--location $LOCATION \
89+
--enable-kafka
90+
91+
# create eventhub for schema history
92+
az eventhubs eventhub create \
93+
--resource-group $RESOURCE_GROUP \
94+
--namespace $EVENTHUB_NAMESPACE \
95+
--name $EVENTHUB_SCHEMA_HISTORY \
96+
--partition-count 1 \
97+
--cleanup-policy Delete \
98+
--retention-time-in-hours 168
7899
```
79100

80101
Later in the configuration process you'll need the EventHubs connection string, so grab it and store it somewhere:
81102

82103
```bash
83-
az eventhubs namespace authorization-rule keys list -g debezium --namespace-name debezium -n RootManageSharedAccessKey --query "primaryConnectionString" -o tsv
104+
RESOURCE_GROUP=debezium
105+
EVENTHUB_NAMESPACE=debezium
106+
107+
az eventhubs namespace authorization-rule keys list \
108+
--resource-group $RESOURCE_GROUP \
109+
--namespace-name $EVENTHUB_NAMESPACE \
110+
--name RootManageSharedAccessKey \
111+
--query "primaryConnectionString" \
112+
--output tsv
84113
```
85114

86115
### Run Debezium
@@ -96,12 +125,12 @@ If prefer a more lean and quick easy to start using Debezium, you can just use t
96125
Docker Compose will use `.env` to get the environment variables values used in the `.yaml` configuration file. The provided `.env.template` file look like the following:
97126

98127
```bash
99-
DEBEZIUM_VERSION=1.6
100-
EH_NAME=debezium
101-
EH_CONNECTION_STRING=
128+
DEBEZIUM_VERSION=2.7
129+
EVENTHUB_NAMESPACE=<eventhub_namespace>
130+
EVENTHUB_CONNECTION_STRING=<eventhub_connection_string>
102131
```
103132

104-
Copy it and create a new `.env` file. Leave the version set to 1.6. Change the `EH_NAME` to the EventHubs name you created before. Also set `EH_CONNECTION_STRING` to hold the EventHubs connection string you got before. Make sure not to use any additional quotes or double quotes.
133+
Copy it and create a new `.env` file. Leave the version set to `2.7`. Change the `EVENTHUB_NAMESPACE` to the EventHubs name you created before. Also set `EVENTHUB_CONNECTION_STRING` to hold the EventHubs connection string you got before. Make sure not to use any additional quotes or double quotes.
105134

106135
#### The .yaml file
107136

@@ -154,38 +183,54 @@ Once the startup has finished, you'll see something like
154183
[Worker clientId=connect-1, groupId=1] Finished starting connectors and tasks [org.apache.kafka.connect.runtime.distributed.DistributedHerder]
155184
```
156185

157-
you will see three topics (or EventHub to use the Azure EventHubs nomenclature):
186+
you will see four topics (or EventHub to use the Azure EventHubs nomenclature):
158187

159188
```bash
160-
az eventhubs eventhub list -g debezium --namespace debezium -o table
189+
190+
RESOURCE_GROUP=debezium
191+
EVENTHUB_NAMESPACE=debezium
192+
193+
az eventhubs eventhub list \
194+
--resource-group $RESOURCE_GROUP \
195+
--namespace-name $EVENTHUB_NAMESPACE \
196+
--output table
161197
```
162198

163199
and the result will show:
164200

165201
- debezium_configs
166202
- debezium_offsets
167203
- debezium_statuses
204+
- schemahistory
168205

169206
to explore Azure Event Hubs is strongly suggest to download and use [Service Bus Explorer](https://github.com/paolosalvatori/ServiceBusExplorer)
170207

171208
#### Register SQL Server Connector
172209

173-
Now that Debezium is running, the SQL Server Connector (which is used both for connecting to Azure SQL or SQL Server) can be registered. Before doing that, make sure to specify the correct connection for your SQL Server instance in the `debezium/register-sqlserver-eh.json` file. You can create one using the provided `.template` file.
210+
Now that Debezium is running, the SQL Server Connector (which is used both for connecting to Azure SQL or SQL Server) can be registered. Before doing that, make sure to specify the correct connection for your SQL Server instance in a file named `sqlserver-connector-config.json`. You can create one using the template file [sqlserver-connector-config.json.template](debezium/sqlserver-connector-config.json.template) file.
174211

175-
If you are using the Wide World Importers database, the only values you have to change are:
212+
Make sure to change the following properties to match your SQL Server configuration:
176213

177214
```json
178-
"database.hostname": "<server>.database.windows.net",
179-
"database.dbname": "<database-name>",
215+
"database.hostname": "<sql_server_name>.database.windows.net",
216+
"database.names": "<db_name>",
217+
"database.user" : "<debezium_user_name>",
218+
"database.password" : "<debezium_user_password>",
180219
```
181220

182-
If you are following the step-by-step guide using a database of yours, make sure to also correctly set values for
221+
You would need to replace `<sql_server_name>`, `<db_name>`, `<debezium_user_name>`, and `<debezium_user_password>` with proper values.
222+
223+
Also, make sure to change the following properties to match your Azure Event Hub configuration:
183224

184225
```json
185-
"database.user" : "debezium-wwi",
186-
"database.password" : "Abcd1234!",
226+
"schema.history.internal.kafka.bootstrap.servers": "<eventhub_namespace>.servicebus.windows.net:9093",
227+
"schema.history.internal.kafka.topic": "<eventhub_schema_history>",
228+
"schema.history.internal.consumer.sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"$ConnectionString\" password=\"<eventhub_connectionstring>\";",
229+
"schema.history.internal.producer.sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"$ConnectionString\" password=\"<eventhub_connectionstring>\";",
187230
```
188231

232+
You would need to replace `<eventhub_namespace>`, `<eventhub_schema_history>`, and `<eventhub_connectionstring>` with proper values.
233+
189234
All the other values used are explained in detail here:
190235

191236
[SQL Server Connector Configuration Values](./documentation/SQL-Server-Connector-Configuration-Value.md)
@@ -253,6 +298,9 @@ Congratulations, you now have a working Change Stream from SQL Server. This open
253298

254299
If you're using Debezium with Azure SQL MI or Azure SQL DB, you may want to run Debezium on Azure. Sample script to run the Debezium container on Azure Container Instances are available in the `debezium/azure` folder.
255300

301+
Please note that the script [01-register-connector.sh](debezium/azure/01-register-connector.sh) will take care of creating the Debezium SQL Server connector configuration JSON file, and then will use it to register a new connector on Debezium.
302+
The generated file will be stored in the `debezium` folder.
303+
256304
### Connector Configuration
257305

258306
More details on SQL Server and Event Hubs specific configuration here:

debezium/azure/00-deploy-debezium.sh

+40-17
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,51 @@
33
# Strict mode, fail on any error
44
set -euo pipefail
55

6-
export DEBEZIUM_VERSION=1.8
7-
export RESOURCE_GROUP="dm-debezium"
8-
export EVENTHUB_NAME="dm-debezium"
9-
export CONTAINER_NAME="dm-debezium"
6+
DEBEZIUM_VERSION=2.7
7+
RESOURCE_GROUP="debezium"
8+
EVENTHUB_NAMESPACE="debezium"
9+
EVENTHUB_SCHEMA_HISTORY="schemahistory"
10+
CONTAINER_NAME="debezium"
11+
LOCATION="WestUS2"
1012

1113
echo "deploying resource group"
12-
az group create -n $RESOURCE_GROUP -l WestUS2
14+
az group create \
15+
--name $RESOURCE_GROUP \
16+
--location $LOCATION
1317

1418
echo "deploying eventhubs namespace"
15-
az eventhubs namespace create -g $RESOURCE_GROUP -n $EVENTHUB_NAME --enable-kafka=true -l WestUS2
19+
az eventhubs namespace create \
20+
--resource-group $RESOURCE_GROUP \
21+
--location $LOCATION \
22+
--name $EVENTHUB_NAMESPACE \
23+
--enable-kafka=true
1624

17-
echo "gathering eventhubs info"
18-
export EH_NAME=`az eventhubs namespace list -g $EVENTHUB_NAME --query '[].name' -o tsv`
19-
export EH_CONNECTION_STRING=`az eventhubs namespace authorization-rule keys list -g $CONTAINER_NAME -n RootManageSharedAccessKey --namespace-name $EVENTHUB_NAME -o tsv --query 'primaryConnectionString'`
25+
echo "deploying schema history event hub"
26+
az eventhubs eventhub create \
27+
--resource-group $RESOURCE_GROUP \
28+
--namespace-name $EVENTHUB_NAMESPACE \
29+
--name $EVENTHUB_SCHEMA_HISTORY \
30+
--partition-count 1 \
31+
--cleanup-policy Delete \
32+
--retention-time-in-hours 168 \
33+
--output none
34+
35+
echo "gathering eventhubs connection string"
36+
EVENTHUB_CONNECTION_STRING=`az eventhubs namespace authorization-rule keys list --resource-group $RESOURCE_GROUP --name RootManageSharedAccessKey --namespace-name $EVENTHUB_NAMESPACE --output tsv --query 'primaryConnectionString'`
2037

2138
echo "deploying debezium container"
22-
az container create -g $RESOURCE_GROUP -n $CONTAINER_NAME \
39+
az container create \
40+
--resource-group $RESOURCE_GROUP \
41+
--location $LOCATION \
42+
--name $CONTAINER_NAME \
2343
--image debezium/connect:${DEBEZIUM_VERSION} \
24-
--ports 8083 --ip-address Public \
25-
--os-type Linux --cpu 2 --memory 4 \
44+
--ports 8083 \
45+
--ip-address Public \
46+
--os-type Linux \
47+
--cpu 2 \
48+
--memory 4 \
2649
--environment-variables \
27-
BOOTSTRAP_SERVERS=${EH_NAME}.servicebus.windows.net:9093 \
50+
BOOTSTRAP_SERVERS=${EVENTHUB_NAMESPACE}.servicebus.windows.net:9093 \
2851
GROUP_ID=1 \
2952
CONFIG_STORAGE_TOPIC=debezium_configs \
3053
OFFSET_STORAGE_TOPIC=debezium_offsets \
@@ -34,13 +57,13 @@ az container create -g $RESOURCE_GROUP -n $CONTAINER_NAME \
3457
CONNECT_REQUEST_TIMEOUT_MS=60000 \
3558
CONNECT_SECURITY_PROTOCOL=SASL_SSL \
3659
CONNECT_SASL_MECHANISM=PLAIN \
37-
CONNECT_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username=\"\$ConnectionString\" password=\"${EH_CONNECTION_STRING}\";" \
60+
CONNECT_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username=\"\$ConnectionString\" password=\"${EVENTHUB_CONNECTION_STRING}\";" \
3861
CONNECT_PRODUCER_SECURITY_PROTOCOL=SASL_SSL \
3962
CONNECT_PRODUCER_SASL_MECHANISM=PLAIN \
40-
CONNECT_PRODUCER_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username=\"\$ConnectionString\" password=\"${EH_CONNECTION_STRING}\";" \
63+
CONNECT_PRODUCER_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username=\"\$ConnectionString\" password=\"${EVENTHUB_CONNECTION_STRING}\";" \
4164
CONNECT_CONSUMER_SECURITY_PROTOCOL=SASL_SSL \
4265
CONNECT_CONSUMER_SASL_MECHANISM=PLAIN \
43-
CONNECT_CONSUMER_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username=\"\$ConnectionString\" password=\"${EH_CONNECTION_STRING}\";"
66+
CONNECT_CONSUMER_SASL_JAAS_CONFIG="org.apache.kafka.common.security.plain.PlainLoginModule required username=\"\$ConnectionString\" password=\"${EVENTHUB_CONNECTION_STRING}\";"
4467

4568
echo "eventhub connection string"
46-
echo $EH_CONNECTION_STRING
69+
echo $EVENTHUB_CONNECTION_STRING

debezium/azure/01-register-connector.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Strict mode, fail on any error
44
set -euo pipefail
55

6-
export RESOURCE_GROUP="dm-debezium"
7-
export CONTAINER_NAME="dm-debezium"
6+
RESOURCE_GROUP="debezium"
7+
CONTAINER_NAME="debezium"
88

99
echo "finding debezium ip"
10-
export DEBEZIUM_IP=`az container show -g $RESOURCE_GROUP -n $CONTAINER_NAME -o tsv --query "ipAddress.ip"`
10+
DEBEZIUM_IP=`az container show --resource-group $RESOURCE_GROUP --name $CONTAINER_NAME --output tsv --query "ipAddress.ip"`
1111

1212
echo "registering connector"
1313
curl -i -X POST \
1414
-H "Accept:application/json" -H "Content-Type:application/json" \
1515
http://${DEBEZIUM_IP}:8083/connectors/ \
16-
-d @../register-sqlserver-eh.json
16+
-d @../sqlserver-connector-config.json

debezium/on-prem/.env.sample

-3
This file was deleted.

debezium/on-prem/.env.template

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DEBEZIUM_VERSION=1.6
2-
EH_NAME=debezium
3-
EH_CONNECTION_STRING=Endpoint=sb://.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=
1+
DEBEZIUM_VERSION=2.7
2+
EVENTHUB_NAMESPACE=<eventhub_namespace>
3+
EVENTHUB_CONNECTION_STRING=<eventhub_connection_string>

debezium/on-prem/delete-connector.ps1

100644100755
File mode changed.

debezium/on-prem/delete-connector.sh

100644100755
File mode changed.

debezium/on-prem/docker-compose.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
ports:
66
- 8083:8083
77
environment:
8-
- BOOTSTRAP_SERVERS=${EH_NAME}.servicebus.windows.net:9093
8+
- BOOTSTRAP_SERVERS=${EVENTHUB_NAMESPACE}.servicebus.windows.net:9093
99
- GROUP_ID=1
1010
- CONFIG_STORAGE_TOPIC=debezium_configs
1111
- OFFSET_STORAGE_TOPIC=debezium_offsets
@@ -15,10 +15,10 @@ services:
1515
- CONNECT_REQUEST_TIMEOUT_MS=60000
1616
- CONNECT_SECURITY_PROTOCOL=SASL_SSL
1717
- CONNECT_SASL_MECHANISM=PLAIN
18-
- CONNECT_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="${EH_CONNECTION_STRING}";
18+
- CONNECT_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="${EVENTHUB_CONNECTION_STRING}";
1919
- CONNECT_PRODUCER_SECURITY_PROTOCOL=SASL_SSL
2020
- CONNECT_PRODUCER_SASL_MECHANISM=PLAIN
21-
- CONNECT_PRODUCER_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="${EH_CONNECTION_STRING}";
21+
- CONNECT_PRODUCER_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="${EVENTHUB_CONNECTION_STRING}";
2222
- CONNECT_CONSUMER_SECURITY_PROTOCOL=SASL_SSL
2323
- CONNECT_CONSUMER_SASL_MECHANISM=PLAIN
24-
- CONNECT_CONSUMER_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="${EH_CONNECTION_STRING}";
24+
- CONNECT_CONSUMER_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="${EVENTHUB_CONNECTION_STRING}";

debezium/on-prem/list-connectors.ps1

100644100755
File mode changed.

debezium/on-prem/list-connectors.sh

100644100755
File mode changed.

debezium/on-prem/register-connector.ps1

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
$JSON = Get-Content '..\register-sqlserver-eh.json' | Out-String
2-
Invoke-RestMethod http://localhost:8083/connectors/ -Method POST -Body $JSON -ContentType "application/json"
1+
$JSON = Get-Content '..\sqlserver-connector-config.json' | Out-String
2+
Invoke-RestMethod http://localhost:8083/connectors/ -Method POST -Body $JSON -ContentType "application/json"

debezium/on-prem/register-connector.sh

100644100755
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/sh
22

3-
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @../register-sqlserver-eh.json -w "\n"
3+
curl -i -X POST \
4+
-H "Accept:application/json" \
5+
-H "Content-Type:application/json" \
6+
http://localhost:8083/connectors/ \
7+
-d @../sqlserver-connector-config.json \
8+
-w "\n"

debezium/on-prem/start-debezium.ps1

100644100755
File mode changed.

debezium/on-prem/start-debezium.sh

100644100755
File mode changed.

debezium/on-prem/stop-debezium.ps1

100644100755
File mode changed.

debezium/on-prem/stop-debezium.sh

100644100755
File mode changed.

debezium/register-sqlserver-eh.json

-22
This file was deleted.

debezium/register-sqlserver-eh.json.template

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "wwi",
3+
"config": {
4+
"snapshot.mode": "schema_only",
5+
"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector",
6+
"database.hostname": "<sql_server_name>.database.windows.net",
7+
"database.port": "1433",
8+
"database.user": "<debezium_user_name>",
9+
"database.password": "<debezium_user_password>",
10+
"database.names": "<db_name>",
11+
"driver.encrypt": "false",
12+
"driver.trustServerCertificate": "true",
13+
"schema.history.internal.kafka.bootstrap.servers": "<eventhub_namespace>.servicebus.windows.net:9093",
14+
"schema.history.internal.kafka.topic": "<eventhub_schema_history>",
15+
"schema.history.internal.consumer.security.protocol": "SASL_SSL",
16+
"schema.history.internal.consumer.sasl.mechanism": "PLAIN",
17+
"schema.history.internal.consumer.sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"$ConnectionString\" password=\"<eventhub_connectionstring>\";",
18+
"schema.history.internal.producer.security.protocol": "SASL_SSL",
19+
"schema.history.internal.producer.sasl.mechanism": "PLAIN",
20+
"schema.history.internal.producer.sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"$ConnectionString\" password=\"<eventhub_connectionstring>\";",
21+
"table.include.list": "Sales.Orders,Warehouse.StockItems",
22+
"tombstones.on.delete": "false",
23+
"topic.prefix": "SQLAzure",
24+
"transforms": "Reroute",
25+
"transforms.Reroute.type": "io.debezium.transforms.ByLogicalTableRouter",
26+
"transforms.Reroute.topic.regex": "(.*)",
27+
"transforms.Reroute.topic.replacement": "wwi"
28+
}
29+
}
30+

0 commit comments

Comments
 (0)