当给定的评估返回 false 时,我需要将消息从父流路由到新流,但当该评估返回 true 时,让它继续在父流中。目前我已经能够使用 Spring Integration DSL.filter()方法成功实现此功能,没有任何问题。但是,我觉得.filter()这样使用似乎并不符合该方法的真正意图。是否有某种类型的路由器可以用来更好地实现同样的需求?是否有必要从这种实现更改.filter()为基于路由器的实现?
以下面的集成流程配置为例......
@Bean
public IntegrationFlow flow() {
return IntegrationFlows
.from("inboundChannel")
.filter(someService::someTrueFalseMethod, onFalseReturn -> onFalseReturn.discardChannel("otherFlowInboundChannel"))
.handle(someService::someHandleMethod)
.get();
}
@Bean
public IntegrationFlow otherFlow() {
return IntegrationFlows
.from("otherFlowInboundChannel")
.handle(someOtherService::someOtherHandleMethod)
.get();
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这似乎.routeToRecipents()可能是我需要使用的。在我的场景中,我需要评估消息的标头,这就是recipientMessageSelector使用它的原因。
@Bean
public IntegrationFlow flow() {
return IntegrationFlows
.from("inboundChannel"
.routeToRecipients(router -> router
.recipientMessageSelector("otherFlowInboundChannel", someService::someTrueFalseMethod)
.defaultOutputToParentFlow()
)
.handle(someService::someHandleMethod)
.get();
}
@Bean
public IntegrationFlow otherFlow() {
return IntegrationFlows
.from("otherFlowInboundChannel")
.handle(someOtherService::someOtherHandleMethod)
.get();
}
Run Code Online (Sandbox Code Playgroud)
即使这个routeToRecipients解决方案似乎有效,它和上面的过滤器实现之间真的有什么好处吗?
spring spring-integration spring-boot spring-integration-dsl