对于最新稳定版本,请使用 Spring Integration 7.0.0spring-doc.cadn.net.cn

积分流组成

消息频道作为春季整合中的一等公民,整合流的组成始终被假设。 流量中任一端点的输入通道都可以用于从任何其他端点发送消息,而不仅仅是从拥有该通道输出端点的端点。 此外,当@MessagingGateway合同、内容丰富器组件、复合端点如<链>,现在集成流程Beans(例如:集成流适配器),它足够简单,可以将业务逻辑分散到更短且可重复使用的部分之间。 最终作文所需的仅仅是关于 的知识消息频道发送或接收。spring-doc.cadn.net.cn

从版本开始5.5.4,进一步抽象消息频道并对最终用户隐藏实现细节,集成流程引入from(IntegrationFlow)工厂方法以允许电流启动集成流程从现有流量的输出中:spring-doc.cadn.net.cn

@Bean
IntegrationFlow templateSourceFlow() {
    return IntegrationFlow.fromSupplier(() -> "test data")
            .channel("sourceChannel")
            .get();
}

@Bean
IntegrationFlow compositionMainFlow(IntegrationFlow templateSourceFlow) {
    return IntegrationFlow.from(templateSourceFlow)
            .<String, String>transform(String::toUpperCase)
            .channel(c -> c.queue("compositionMainFlowResult"))
            .get();
}

另一方面,集成流程定义已添加to(IntegrationFlow)端子作符继续在其他流的输入通道上流动电流:spring-doc.cadn.net.cn

@Bean
IntegrationFlow mainFlow(IntegrationFlow otherFlow) {
    return f -> f
            .<String, String>transform(String::toUpperCase)
            .to(otherFlow);
}

@Bean
IntegrationFlow otherFlow() {
    return f -> f
            .<String, String>transform(p -> p + " from other flow")
            .channel(c -> c.queue("otherFlowResultChannel"));
}

流动中间的组成可以用现有的gateway(IntegrationFlow)EIP方法。 这样,我们可以通过从更简单、可重用的逻辑块组合出任意复杂度的流程。 例如,你可以添加一个库集成流程Beans 作为依赖,只需将配置类导入最终项目并自动布线即可集成流程定义。spring-doc.cadn.net.cn