Created
July 19, 2019 12:34
-
-
Save hpgrahsl/a6452eba5cd0bc527b59abdebd1f260e to your computer and use it in GitHub Desktop.
OutboxListener Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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