对于最新的稳定版本,请使用 Spring Integration 6.4.0! |
DSL 和端点配置
都IntegrationFlowBuilder
EIP 方法有一个变体,该变体应用 lambda 参数来提供AbstractEndpoint
实例:SmartLifecycle
,PollerMetadata
,request-handler-advice-chain
等。
它们中的每一个都有通用参数,因此它允许您配置终端节点,甚至其MessageHandler
在上下文中,如下例所示:
@Bean
public IntegrationFlow flow2() {
return IntegrationFlow.from(this.inputChannel)
.transformWith(t -> t
.transformer(new PayloadSerializingTransformer())
.autoStartup(false)
.id("payloadSerializingTransformer"))
.transformWith(t -> t
.transformer((Integer p) -> p * 2)
.advice(expressionAdvice()))
.get();
}
此外,EndpointSpec
提供了一个id()
方法,让您使用给定的 bean 名称而不是生成的 bean 名称注册端点 bean。
如果MessageHandler
作为 Bean 引用,则任何现有的adviceChain
如果.advice()
method 的 API 定义中:
@Bean
public TcpOutboundGateway tcpOut() {
TcpOutboundGateway gateway = new TcpOutboundGateway();
gateway.setConnectionFactory(cf());
gateway.setAdviceChain(Collections.singletonList(fooAdvice()));
return gateway;
}
@Bean
public IntegrationFlow clientTcpFlow() {
return f -> f
.handle(tcpOut(), e -> e.advice(testAdvice()))
.transform(Transformers.objectToString());
}
它们不会被合并,只有testAdvice()
在这种情况下使用 bean。