Skip to content

Latest commit

 

History

History

debezium

CDC with Debezium example

Start Zookeeper, Kafka, PostgreSQL, and Kafka Connect:

docker compose up

In another terminal, run the Quarkus application in /chapter-9/debezium:

mvn clean package
java -jar target/quarkus-app/quarkus-run.jar

Create Postgres connector

curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @register.json

Verify Postgres connector was created

curl -H "Accept:application/json" localhost:8083/connectors/

Verify configuration of the Postgres connector

curl -X GET -H "Accept:application/json" localhost:8083/connectors/customer-connector

Verify topics created for tables

docker exec -ti kafka bin/kafka-topics.sh --list --zookeeper zookeeper:2181

Consume messages from the Customer table topic

docker-compose exec kafka /kafka/bin/kafka-console-consumer.sh \
    --bootstrap-server kafka:9092 \
    --from-beginning \
    --property print.key=true \
    --topic quarkus-db-server.public.customer

Upon starting, four messages will be processed representing the four customers that were loaded by the Quarkus application upon starting. If you don't want to see those messages, remove --from-beginning in the above command.

Trigger customer updates

In another terminal, create or update customer data to see the messages appear.

Update a customer name

curl -X PUT -H "Content-Type:application/json" http://localhost:8080/customer/2 -d '{"id" : 2, "name" : "Marsha Willis"}'

Create a new customer

curl -X POST -H "Content-Type:application/json" http://localhost:8080/customer -d '{"name" : "Harry Houdini"}'

Shut down

When finished, run the below to stop and remove the services:

docker compose stop
docker compose rm