Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Integration DSL - Wait for input from channel in the flow

I wonder if it's possible in spring integration to include an external channel in the flow. So I have http inbound gateway flow, and after it's triggered it should communicate with other process via udp ports. My biggest concern is how to receive a message from udp port inside this flow.

@Bean
public IntegrationFlow httpInboundGatewayFlow() {
    return IntegrationFlows.from(Http.inboundGateway(httpInboundPath))
             .transform(niUdpRequestTransformer())
             /*sending a message to udp port*/
             .publishSubscribeChannel(runnable -> runnable
                  .subscribe(flow -> flow                      
                      .handle(udpOutboundChannel())))
            /*wait for input from udpResponse channel here (HOW TO?)*/
            /*process udpInboundFlow message*/
            .handle((payload, headers) -> successNetworkResponse())))
            .transform(new ObjectToJsonTransformer())
            .handle((payload, headers) -> payload)
            .get();
}

@Bean
public IntegrationFlow udpInboundFlow() {
    return IntegrationFlows.from(udpInboundChannel())
            .transform(niUdpResponseTransformer())
            .channel("udpResponse")
            .get();
}

Using udpInboundFlow should be implemented as some kind of poller which checks if correct message has arrived.

Thanks for your help.

like image 870
Stevan Avatar asked Jan 23 '26 08:01

Stevan


1 Answers

What you are talking about is called correlation. And I somehow believe that you would like to get some kind of reply to that request to UDP.

So, what you need is indeed like this:

.channel("udpResponse")
.aggregate(...)

You should figure out some correlationKey for the request message and ensure the reply from UDP has the same key. The aggregator should be configured for the .releaseStrategy(group -> group.size() == 2).

Where the first message will be the request one and the second is indeed as a result from the external udpResponse.

See Reference Manual for more info.

like image 131
Artem Bilan Avatar answered Jan 25 '26 21:01

Artem Bilan