Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.28 KB

postgres-cdc.md

File metadata and controls

50 lines (38 loc) · 1.28 KB

Publish Postgres changes to MQTT, Kafka, Clickhouse, etc

  1. Start Postgres and EMQX MQTT broker
curl -OL https://raw.githubusercontent.com/edgeflare/pgo/refs/heads/main/docs/docker-compose.yaml
docker compose up -d
  1. Create a test table, eg users
PGUSER=postgres PGPASSWORD=secret PGHOST=localhost PGDATABASE=testdb psql
CREATE TABLE users (
  id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  name TEXT
);
  1. Start logrepl
export PGO_POSTGRES_LOGREPL_CONN_STRING="postgres://postgres:secret@localhost:5432/testdb?replication=database"
export PGO_POSTGRES_LOGREPL_TABLES=users
go build ./cmd/pgo/...
./pgo pipeline --config pkg/config/config.example.yaml
  1. Subscribe
  • MQTT: /pgcdc/<tableName> topic (testing with mosquitto client)
mosquitto_sub -t /pgcdc/users # supply additional args eg username,password etc
  • Kafka: test topic. use any kafka client eg kaf
echo | kaf produce test # ensusure test topic is created
kaf consume test --follow # consume messages until program execution
  1. INSERT (or update etc) into users table and notice MQTT subscriber receiving the message
INSERT INTO users (name) VALUES ('alice');
INSERT INTO users (name) VALUES ('bob');