【发布时间】:2021-07-15 20:38:54
【问题描述】:
为了使我的 Spring Integration DSL 代码更具可读性和模块化,我想将像 .scatterGather() 这样的复杂操作提取到子流中。
以此为例说明重构前代码的外观:
@Bean
IntegrationFlow testFlow() {
return IntegrationFlows
.from(Http.inboundChannelAdapter("test").get())
.scatterGather(
s -> s
.applySequence(true)
.recipientFlow(getSubFlow2()),
g -> g.outputProcessor(MessageGroup::getOne))
.log(INFO, m -> m)
.routeToRecipients(route -> route
.recipientFlow(IntegrationFlowDefinition::nullChannel)
.get())
.get();
}
private IntegrationFlow getSubFlow2() {
return f -> f.handle((m, h) -> 42);
}
这是我想提取到它自己的子流程和方法中的部分:
.scatterGather(
s -> s
.applySequence(true)
.recipientFlow(getSubFlow2()),
g -> g.outputProcessor(MessageGroup::getOne))
.log(INFO, m -> m)
我想象结果看起来像这样:
@Bean
IntegrationFlow testFlow() {
return IntegrationFlows
.from(Http.inboundChannelAdapter("test").get())
.someMethod(getSubFlow1())
.routeToRecipients(route -> route
.recipientFlow(IntegrationFlowDefinition::nullChannel)
.get())
.get();
}
private IntegrationFlow getSubFlow1() {
return f -> f
.scatterGather(
s -> s
.applySequence(true)
.recipientFlow(getSubFlow2()),
g -> g.outputProcessor(MessageGroup::getOne))
.logAndReply(INFO, m -> m)
}
private IntegrationFlow getSubFlow2() {
return f -> f.handle((m, h) -> 42);
}
这可以通过 Spring Integration DSL 以某种方式完成吗?怎么样?
【问题讨论】:
标签: spring-integration spring-integration-dsl