Skip to content

Commit

Permalink
Expand README
Browse files Browse the repository at this point in the history
  • Loading branch information
rieske committed Nov 1, 2023
1 parent 8e02f82 commit 793620e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ To install the plugin on a self-hosted instance, refer to the plugin's documenta

## Usage

```java
Consumer<DatabaseChange> cdcConsumer = databaseChange -> {
// Do something useful here. Perhaps, relay the change to some message broker.
System.out.println(databaseChange);
};

ChangeDataCapture cdc = ChangeDataCapture.create(
jdbcUrl,
databaseUser,
databasePassword,
replicationSlotName,
Set.of("public.some_table", "public.some_other_table"),
cdcConsumer
);

// safe to call if the slot already exists
cdc.createReplicationSlot();

// make sure the streaming is stopped gracefully on SIGTERM
Runtime.getRuntime().addShutdownHook(new Thread(() -> cdc.stop()));

// start streaming changes to the consumer
cdc.start();
```

As long as the replication slot exists, unconsumed/unacknowledged changes will pile up.
When a consumer is stopped, no change will be lost, and the next consumer will start consuming
from the last unacknowledged change.

Note: leaving the replication slot without a consumer for an extended period of time will consume database
instance's storage space and in extreme cases can cause the database to shut down.
If a replication slot is no longer required, it should be dropped.

## Testing

Expand Down

0 comments on commit 793620e

Please sign in to comment.