3

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.

Stevan
  • 1,933
  • 1
  • 18
  • 19

1 Answers1

2

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118