You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring IntegrationFlow配置handle后调用Http.outboundGateway报错如何解决

问题根因
  • 你配置中的第一个handle()方法使用了无返回值的lambda表达式,属于单向MessageHandler,执行完成后不会向下游传递消息,所以后续再添加Http.outboundGateway处理节点就会抛出流已终止的错误。
  • 你当前这段代码的逻辑是要将原消息转换为新的SearchRequestB对象,属于典型的消息转换场景,应该使用transform()算子,或者改用带返回值的handle()重载方法。
修复后的配置代码
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class IntegrationConfig {
    @Bean
    public IntegrationFlow sayHelloFlow(){
        String uri = "http://localhost:8081/hellos";
        return IntegrationFlows.from("integration.example.gateway.channel")
                .filter("headers['operation'] == 'OPERATION_A'")
                // 改用transform做消息转换,返回值会作为新的消息载荷向下游传递
                .<SearchRequest, SearchRequestB>transform((request) -> {
                    Map<String, String> header = new HashMap<>();
                    header.put("a_header", request.getHeaders().get("initial_val", String.class));
                    return new SearchRequestB(
                            request.getPayload()+"Modified",
                            header);
                })
                .handle(Http.outboundGateway(uri).httpMethod(HttpMethod.POST))
                // 适配Gateway返回值类型,将HTTP接口返回结果转为字符串
                .<Object, String>transform(Object::toString)
                .get();
    }
}  
额外说明

如果坚持使用handle实现,可选择支持返回值的handle(GenericHandler)重载方法,写法和上述transform逻辑完全一致,仅需要替换方法名为handle即可。

内容的提问来源于stack exchange,提问作者Dnyaneshwar Jadhav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 09:30:05