此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

通常,消息流从入站通道适配器(如 )启动。 适配器配置了 ,它要求 定期生成消息。 Java DSL 也允许从 开始。 为此,fluent API 提供了一个重载方法。 您可以将 配置为 bean,并将其作为该方法的参数提供。 的第二个参数是一个 lambda,它允许您为 . 以下示例演示如何使用 Fluent API 和 lambda 创建:<int-jdbc:inbound-channel-adapter><poller>MessageSource<?>IntegrationFlowMessageSource<?>IntegrationFlowIntegrationFlow.from(MessageSource<?> messageSource)MessageSource<?>IntegrationFlow.from()Consumer<SourcePollingChannelAdapterSpec>PollerMetadataSmartLifecycleSourcePollingChannelAdapterIntegrationFlowSpring中文文档

@Bean
public MessageSource<Object> jdbcMessageSource() {
    return new JdbcPollingChannelAdapter(this.dataSource, "SELECT * FROM something");
}

@Bean
public IntegrationFlow pollingFlow() {
    return IntegrationFlow.from(jdbcMessageSource(),
                c -> c.poller(Pollers.fixedRate(100).maxMessagesPerPoll(1)))
            .transform(Transformers.toJson())
            .channel("furtherProcessChannel")
            .get();
}

对于不需要直接生成对象的情况,可以使用基于 的变体。 的结果会自动包装在 (如果还不是 )。MessageIntegrationFlow.fromSupplier()java.util.function.SupplierSupplier.get()MessageMessageSpring中文文档