Skip to content

OrcunColak/java-jdbc-postgres-tutorial

Repository files navigation

The original idea is from
https://medium.com/@kanhaaggarwal/kafka-is-overkill-event-sourcing-with-just-postgres-and-spring-boot-fcd587fea2e2

1. Enable Logical Replication on PostgreSQL

postgresql.conf

Enable Logical Replication on PostgreSQL

wal_level = logical max_replication_slots = 10 max_wal_senders = 10

pg_hba.conf

Ensure replication is allowed in pg_hba.conf: host replication your_user 0.0.0.0/0 md5

Then restart Postgres

2. Create a Publication and Slot

SQL

CREATE PUBLICATION spring_pub FOR TABLE orders, customers;

-- Create a logical replication slot
SELECT * FROM pg_create_logical_replication_slot('spring_slot', 'pgoutput');

or use wal2json if you prefer JSON payloads:
SELECT * FROM pg_create_logical_replication_slot('spring_slot', 'wal2json');

3. Use PGReplicationStream

Write Java code to listen to events using PGReplicationStream

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages