1

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.

2 Answers 2

1

It would be great if you show how you process a business data before sending it into this domain.event.sender channel for storing into so-called outbox table.

However it is just pretty simple to make this domain.event.sender as a PublishSubscribeChannel and have another subscriber which would do the logic you are asking. If you don't configure this channel for a TaskExecutor, both subscribers will process the same message sequentially and withing the same business transaction.

See more info in docs: https://docs.spring.io/spring-integration/reference/channel/implementations.html#channel-implementations-publishsubscribechannel

Sign up to request clarification or add additional context in comments.

Comments

0

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()));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.