<center><h1>Setting up cdc->kafka cluster with debezium on windows </h1></center> <h2> Step1-Installing Java /Scala </h2> * First thing we need to check if Java 8 is installed or not ``` java --version ``` * If the Java version is 8 .it means that your machine has java already installed . else install java . * https://www.oracle.com/java/technologies/javase-jdk13-downloads.html <h2> Step 2- Setup CDC </h2> * CDC will only work on sql server enterprise and sql developer so please ensure that sql server version is correct * Use below scripts to activate cdc to db and table ``` USE DatabaseName GO EXEC sys.sp_cdc_enable_db GO ``` * Enable for table. ``` USE MyDB GO EXEC sys.sp_cdc_enable_table @source_schema = N’dbo’, @source_name = N’TableName’, @role_name = N’RoleName’, @supports_net_changes = 1 GO ``` * To view the CDC configuration for your tables ``` USE MyDB GO EXEC sys.sp_cdc_help_change_data_capture GO ``` * Now that CDC is enabled lets setup kafka cluster <h2> Step 3- Setup kafka cluster </h2> * Download kafka https://kafka.apache.org/downloads and unzip to your required folder * Download Zookeeper https://zookeeper.apache.org/releases.html and extract to your required folder * Set env variable ZOOKEEPER_HOME to ~Zookeeper/bin relevant path * open cmd and execute zkserver to check if its working * Add ~/Zookeeper/bin. to Path env variable ``` zkserver ``` * Setup zookeeper config in ~:/Zookeeper/conf/zoo.cfg ``` dataDir=E:/MiscDownloads/KafkaMisc/Zookeeper/apache-zookeeper-3.6.0-bin/data ``` * Setup kafka properties in ~:/Kafka/conf/server.properties ``` log.dirs= E:/MiscDownloads/KafkaMisc/Kafka_downloads/kafka_2.11-2.4.0/logs. group.initial.rebalance.delay.ms=0 ``` * start zookeeper by below ``` zkserver ``` * start kafka cluster ``` E:\kafka_2.11-2.4.0\bin\windows\kafka-server-start.bat ``` <h2> Step 4- Setup debezium </h2> * download debezium and extract it to plugins folder in kafka directory https://debezium.io/releases/0.10/ * create connector.properties in notepad and save in kafka directory ``` name=192.168.3.20 connector.class=io.debezium.connector.sqlserver.SqlServerConnector database.hostname=192.168.3.20 database.port=1433 database.user=username database.password=pw database.applicationIntent=ReadOnly database.dbname=myCMTest_Internal_4.0 database.server.name=192.168.3.20 table.whitelist=dbo.CRS_Partner database.history.kafka.bootstrap.servers=localhost:9092 database.history.kafka.topic=CRSPartner #If kafka is TLS authenticated, uncomment below lines. #database.history.producer.security.protocol=SSL #database.history.producer.ssl.truststore.location=/tmp/kafka.client.truststore.jks ``` * please note that debezium will only publish changes to host/servername.dbo.tablename * create worker.properties in notepad and save in kafka directory ``` offset.storage.file.filename=D:/kafka/kafka_2.11-2.4.0/tmp/connect.offsets bootstrap.servers=localhost:9092 offset.flush.interval.ms=10000 internal.key.converter=org.apache.kafka.connect.json.JsonConverter internal.value.converter=org.apache.kafka.connect.json.JsonConverter internal.key.converter.schemas.enable=false internal.value.converter.schemas.enable=false key.converter=org.apache.kafka.connect.json.JsonConverter value.converter=org.apache.kafka.connect.json.JsonConverter plugin.path=D:/Kafka/kafka_2.11-2.4.0/plugins #If kafka is TLS authenticated, uncomment below lines. #security.protocol=SSL #ssl.truststore.location=/tmp/kafka.client.truststore.jks #producer.security.protocol=SSL #producer.ssl.truststore.location=/tmp/kafka.client.truststore.jks ``` * Please note despite declaration of topic name in connector debezium will publish cdc changes onto hostname.dbo.tablename topic * Start connector ``` E:\kafka_2.11-2.4.0\bin\windows\connect-standalone.bat ``` * Connector is your producer .. start consuming the topic ``` bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic topicName --from-beginning ``` * make changes in your table... you will see the results here .. <h2> if you face any difficulties you can simply download my kafka-debeziyum and zookeeper folders * https://drive.google.com/drive/folders/17c8eNwqJI-jvQwGepY0XR7e8cHayz_UL?usp=sharing * Note that you have to set zookeeper, kafka , connector and worker properties