此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1! |
DSL 扩展
从 5.3 版开始,IntegrationFlowExtension
已引入以允许使用自定义或组合的 EIP 运算符扩展现有的 Java DSL。
所需要的只是该类的扩展,它提供了可在IntegrationFlow
bean 定义。
扩展类也可用于自定义IntegrationComponentSpec
配置;例如,可以在现有的IntegrationComponentSpec
外延。
下面的示例演示了复合自定义运算符和AggregatorSpec
默认自定义的扩展outputProcessor
:
public class CustomIntegrationFlowDefinition
extends IntegrationFlowExtension<CustomIntegrationFlowDefinition> {
public CustomIntegrationFlowDefinition upperCaseAfterSplit() {
return split()
.transform("payload.toUpperCase()");
}
public CustomIntegrationFlowDefinition customAggregate(Consumer<CustomAggregatorSpec> aggregator) {
return register(new CustomAggregatorSpec(), aggregator);
}
}
public class CustomAggregatorSpec extends AggregatorSpec {
CustomAggregatorSpec() {
outputProcessor(group ->
group.getMessages()
.stream()
.map(Message::getPayload)
.map(String.class::cast)
.collect(Collectors.joining(", ")));
}
}
对于方法链流,这些扩展中的新 DSL 运算符必须返回扩展类。
这样一个目标IntegrationFlow
definition 将适用于新的和现有的 DSL 运算符:
@Bean
public IntegrationFlow customFlowDefinition() {
return
new CustomIntegrationFlowDefinition()
.log()
.upperCaseAfterSplit()
.channel("innerChannel")
.customAggregate(customAggregatorSpec ->
customAggregatorSpec.expireGroupsUponCompletion(true))
.logAndReply();
}