We want to implement an Outbox pattern by using spring integration. Starting from this example, we came up with this simpeler solution:
protected IntegrationFlowDefinition<?> buildFlow() {
return from("domain.event.sender")
.channel(c -> c.queue(this.jdbcMessageStore, "outbox"))
.handle(
this.messagePublisherHandler,
c -> c.poller(poller -> poller.fixedDelay(1000).transactional()));
}
This solution will take a message from "domain.event.sender", store it in the database (in case of an error) and then POLL this db to send a message to a MessageBus (via messagePublisherHandler).
We want to have a solution that will ALSO process this message immediately after transaction synchronisation, without that we have to wait for the poller to finish.
It was a stupid answer. I just needed to change the fixedDelay
to 0
:
protected IntegrationFlowDefinition<?> buildFlow() {
return from("domain.event.sender")
.channel(c -> c.queue(this.jdbcMessageStore, "outbox"))
.handle(
this.messagePublisherHandler,
c -> c.poller(poller -> poller.fixedDelay(0).transactional()));
}