I am needing to route a message from my parent flow into a new flow when a given evaluation returns false but have it continue in the parent flow when that evaluation returns true. Currently I have been able to successfully implement this functionality using the Spring Integration DSL .filter()
method without any issues. However, I feel as if though using .filter()
in this way does not fall under the true intention of this method. Is there a certain type of router that can be used to better achieve this same need? Is it necessary to change from this .filter()
implementation to a router based implementation?
Given the below Integration Flow configuration as an example...
@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();
}
Up to this point it seems .routeToRecipents()
might be what I need to use. In my scenario, I need to evaluate the headers of the message so that is why the recipientMessageSelector
is being used.
@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();
}
Even with this routeToRecipients
solution that appears to work, is there really any benefit gained between it and the filter implementation above?