【发布时间】:2020-05-30 13:37:03
【问题描述】:
当给定评估返回 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();
}
到目前为止,似乎.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();
}
即使这个routeToRecipients 解决方案似乎有效,它和上面的过滤器实现之间真的有什么好处吗?
【问题讨论】:
标签: spring spring-boot spring-integration spring-integration-dsl