Christoph Dahlen
Christoph Dahlen

Reputation: 836

Order of "subscribing" Spring Integration Flows when using Java SDL

Referencing rather ancient question Spring Integration "Publish Subscribe Channel" with Spring DSL, I need to know wether it is possible to determine / declare the order of which subscribers of a publish/subscriber-channel will be called.

Reason: I am receiving files from a remote directory to transfer them into a database and delete afterwards. Of course, deletion shall only happen, if writing to the database completed successfully.

Code from referenced question is:

@Bean
public SubscribableChannel  httpInAdapterPubSubChannel()
{
    return MessageChannels.publishSubscribe("httpInAdapterPubSubChannel")
    .get();
}

@Bean
public IntegrationFlow subscriber1() {
    return IntegrationFlows.from(httpInAdapterPubSubChannel())
            .handle( message -> System.out.println("Enrich Headers based on Payload...."))
            .get();
}

@Bean
public IntegrationFlow subscriber2() {
     return IntegrationFlows.from(httpInAdapterPubSubChannel())
                .handle( message -> System.out.println("Save Payload to Audit Table..."))
                .get();
}

Upvotes: 0

Views: 134

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121262

The order is an attribute of the endpoint which is going to subscribe to the channel. In your case we have those two .handle() endpoints and here is an option how to configure:

.handle( message -> System.out.println("Enrich Headers based on Payload...."),
           e -> e.order(1))

 .handle( message -> System.out.println("Save Payload to Audit Table..."),
           e -> e.order(2))

See docs for more info: https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-endpoints

Upvotes: 0

Related Questions