跳到主要内容
版本:7.0.2

DSL 与端点配置

DeepSeek V3 中英对照 DSL and Endpoint Configuration

所有 IntegrationFlowBuilder EIP 方法都包含一个变体,该变体应用 lambda 参数来为 AbstractEndpoint 实例提供选项:SmartLifecyclePollerMetadatarequest-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。

如果 MessageHandler 被引用为 bean,那么当 DSL 定义中存在 .advice() 方法时,任何现有的 adviceChain 配置都将被覆盖:

@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。