Skip to content

Instantly share code, notes, and snippets.

@hpgrahsl
Created July 19, 2019 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpgrahsl/a6452eba5cd0bc527b59abdebd1f260e to your computer and use it in GitHub Desktop.
Save hpgrahsl/a6452eba5cd0bc527b59abdebd1f260e to your computer and use it in GitHub Desktop.
OutboxListener Class
@Component
public class OutboxListener {
private OutboxEventRepository repository;
public OutboxListener(OutboxEventRepository repository) {
this.repository = repository;
}
@EventListener
public void onExportedEvent(Outboxable event) {
OutboxEvent outboxEvent = OutboxEvent.from(event);
// The outbox event will be written to the "outbox" table
// and immediately afterwards removed again. Thus the
// "outbox" table is effectively empty all the time. From a
// CDC perspective this will produce an INSERT operation
// followed by a DELETE operation of the same record such that
// both events are captured from the database log by Debezium.
repository.save(outboxEvent);
repository.delete(outboxEvent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment