Giter Club home page Giter Club logo

postgresql-change-data-capture-using-debezium's Introduction

postgresql-change-data-capture-using-debezium

PostgreSQL Change Data Capture (CDC) Using Debezium

  1. Create containers
docker-compose up
  1. Get-into postgresql container to create database & table
CREATE DATABASE payment;
\c payment
CREATE TABLE transaction(id SERIAL PRIMARY KEY, amount int, customerId varchar(36));
  1. Define a postgres-connector
curl -X POST -H "Accept:application/json" -H "Content-Type:application/json" localhost:8083/connectors/ -d '
{
 "name": "payment-connector",
 "config": {
 "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
 "tasks.max": "1",
 "database.hostname": "postgres",
 "database.port": "5432",
 "database.user": "appuser",
 "database.password": "qwerty",
 "database.dbname" : "payment",
 "database.server.name": "dbserver1",
 "database.whitelist": "payment",
 "database.history.kafka.bootstrap.servers": "kafka:9092",
 "database.history.kafka.topic": "schema-changes.payment"
 }
}'
  1. Get-into kafka container to list the topic that you have created.
kafka-topics --zookeeper zookeeper:2181 --list
  1. Create a consumer to consume db tracking messages
kafka-console-consumer --bootstrap-server kafka:9092 --from-beginning --topic dbserver1.public.transaction --property print.key=true --property key.separator="-"
  1. Insert into transaction than update it
insert into transaction(id, amount,customerId) values(85, 87,'37b920fd-ecdd-7172-693a-d7be6db9792c');
update transaction set amount=77 where id=85

You will see the messages consumed by consumer as blow;

Insert message-payload with "op" : "c"

{
   "payload":{
      "before":null,
      "after":{
         "id":85,
         "amount":87,
         "customerid":"37b920fd-ecdd-7172-693a-d7be6db9792c"
      },
      "source":{
         "version":"1.0.2.Final",
         "connector":"postgresql",
         "name":"dbserver1",
         "ts_ms":1583931003883,
         "snapshot":"false",
         "db":"payment",
         "schema":"public",
         "table":"transaction",
         "txId":568,
         "lsn":23936360,
         "xmin":null
      },
      "op":"c",
      "ts_ms":1583931003889
   }
}

Update message-payload with "op" : "u"

{
   "payload":{
      "before":null,
      "after":{
         "id":85,
         "amount":77,
         "customerid":"37b920fd-ecdd-7172-693a-d7be6db9792c"
      },
      "source":{
         "version":"1.0.2.Final",
         "connector":"postgresql",
         "name":"dbserver1",
         "ts_ms":1583931065480,
         "snapshot":"false",
         "db":"payment",
         "schema":"public",
         "table":"transaction",
         "txId":569,
         "lsn":23936888,
         "xmin":null
      },
      "op":"u",
      "ts_ms":1583931065486
   }
}

postgresql-change-data-capture-using-debezium's People

Contributors

canertosuner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.