Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Latest commit

 

History

History
 
 

connect-jdbc-postgresql-sink

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

JDBC PostgreSQL sink connector

asciinema

Objective

Quickly test JDBC PostGreSQL connector.

How to run

Simply run:

$ ./postgres-sink.sh

Details of what the script is doing

Creating JDBC PostgreSQL sink connector

$ curl -X PUT \
     -H "Content-Type: application/json" \
     --data '{
               "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
                    "tasks.max": "1",
                    "connection.url": "jdbc:postgresql://postgres/postgres?user=postgres&password=postgres&ssl=false",
                    "topics": "orders",
                    "auto.create": "true"
          }' \
     http://localhost:8083/connectors/postgres-sink/config | jq .

Sending messages to topic orders

$ docker exec -i connect kafka-avro-console-producer --broker-list broker:9092 --property schema.registry.url=http://schema-registry:8081 --topic orders --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"id","type":"int"},{"name":"product", "type": "string"}, {"name":"quantity", "type": "int"}, {"name":"price",
"type": "float"}]}' << EOF
{"id": 999, "product": "foo", "quantity": 100, "price": 50}
EOF

Show content of ORDERS table:

$ docker exec postgres bash -c "psql -U postgres -d postgres -c 'SELECT * FROM ORDERS'"

Results:

 product | quantity | price | id
---------+----------+-------+-----
 foo     |      100 |    50 | 999

N.B: Control Center is reachable at http://127.0.0.1:9021