I want to use togglz to decide the routing of my flow
I have the FeatureManager
in my Integration Flow:
@Autowired
private FeatureManager manager
and later on:
return IntegrationFlows
.from("incoming-flow")
.routeToRecipients(route -> {
if (manager.isActive(MyFeatures.A_B_TESTING)) {
route.recipient(A_CHANNEL);
} else {
route.recipient(DEFAULT_CHANNEL);
}
})
This is unfortunately not working, as the route is decided upon bean creation, which means that for this to work I would have to restart my application every time I change the toggle. Which defeats the purpose of the toggle.
I can think of ways of doing this, by creating filters and other flows, but is there any way of doing this? I've found some documenation of Spring, but it doesn't seem useful and it's written in xml, which I'm not using.
CodePudding user response:
What you do is really not for runtime decision. The recipient()
is to add a mapping to the recipient list router. What you probably need is a decision at runtime where to route the current message. For the purpose I'd suggest to look into a plain route()
and its function support:
.route(p -> manager.isActive(MyFeatures.A_B_TESTING) ? A_CHANNEL : DEFAULT_CHANNEL)
The recipient list router is really for other use-cases when we need to decide to send a message to several mapped channels according their selectors. Well, that can be done with regular router as well, but there is more formal Recipient List router EI pattern which we follow here.
What you really need here is really a plain router with runtime evaluation and appropriate channel (or its name) return.
Point, please, us to the documentation which confuses you and we will do our best to improve it.