Reputation: 3344
Is it possible don't to create a new channel after Router usage in Spring Integration in such scenario:
HeaderValueRouter
)Here steps 1-2 isn't actually define different paths of execution but only temp branching.
Currently I have to extract 3 and others integration steps into a separate flow definition with a new direct input channel and use this channel name at step 2. The solution looks artificial and cumbersome.
May I don't do this somehow?
Upvotes: 1
Views: 323
Reputation: 121542
First of all let's take a look at like it is an EIP component:
a Message Router, which consumes a Message from one Message Channel and republishes it to a different Message Channel channel depending on a set of conditions.
From other side to reach the best loosely coupling and better modularity, the router knows nothing about donwstream flow - just only its input channel to router.
If you would like to have some simple if...else
logic, but don't involve the messaging in the logic, you could just compose that logic in some POJO method and with the .handle()
you will be able to reach the desired behavior.
The router must only route, nothing more!
From other side to make the DSL a bit useful we have introduced the subflow
notation and you can map routing logic using subFlowMapping
:
@Bean
public IntegrationFlow routerTwoSubFlows() {
return f -> f
.split()
.<Integer, Boolean>route(p -> p % 2 == 0, m -> m
.subFlowMapping("true", sf -> sf.<Integer>handle((p, h) -> p * 2))
.subFlowMapping("false", sf -> sf.<Integer>handle((p, h) -> p * 3)))
.aggregate()
.channel(c -> c.queue("routerTwoSubFlowsOutput"));
}
The
.channelMapping()
continues to work as in regular Router mapping, but the.subFlowMapping()
tied that subflow with main flow. In other words, any router's subflow returns to the main flow after.route()
.
Upvotes: 1