对于最新稳定版本,请使用 Spring Integration 7.0.0spring-doc.cadn.net.cn

入站通道适配器

通常,消息流从入站通道适配器开始(例如<int-jdbc:入站通道适配器>). 适配器配置为<poller>,并且它会问一个MessageSource<?>定期发送消息。 Java DSL 允许启动集成流程来自MessageSource<?>太。 为此,集成流程流利的API提供了超载IntegrationFlow.from(MessageSource<?> messageSource)方法。 你可以配置MessageSource<?>作为一个豆子,并以此作为该方法的论据。 第二个参数IntegrationFlow.from()Consumer<SourcePollingChannelAdapterSpec>lambda 允许你提供选项(例如Poller元数据SmartLifecycleSourcePollingChannelAdapter. 以下示例展示了如何使用流流API和λ来创建集成流程:spring-doc.cadn.net.cn

@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();
}

对于那些没有建造需求的情况消息直接使用对象,你可以使用IntegrationFlow.fromSupplier()基于java.util.function.Supplier. 结果Supplier.get()自动被包裹在消息(如果它还不是消息).spring-doc.cadn.net.cn