简体   繁体   English

Spring Integration DSL - 等待流中的通道输入

[英]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. 所以我有http入站网关流,在它被触发后,它应该通过udp端口与其他进程通信。 My biggest concern is how to receive a message from udp port inside this flow. 我最关心的是如何从此流程中的udp端口接收消息。

@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. 使用udpInboundFlow应该被实现为某种轮询器,它检查是否有正确的消息到达。

Thanks for your help. 谢谢你的帮助。

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. 而且我不知何故相信您希望得到某种对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. 您应该为请求消息找出一些correlationKey ,并确保来自UDP的回复具有相同的密钥。 The aggregator should be configured for the .releaseStrategy(group -> group.size() == 2) . 聚合器应配置为.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 . 第一条消息将是请求1,第二条消息确实是外部udpResponse的结果。

See Reference Manual for more info. 有关详细信息,请参见参考手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM