|
此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1! |
入站通道适配器
通常,消息流从入站通道适配器(例如<int-jdbc:inbound-channel-adapter>).
适配器配置为<poller>,它会询问一个MessageSource<?>定期生成消息。
Java DSL 允许启动IntegrationFlow从MessageSource<?>太。
为此,该IntegrationFlowFluent API 提供了一个重载的IntegrationFlow.from(MessageSource<?> messageSource)方法。
您可以配置MessageSource<?>作为 bean 并将其作为该方法的参数提供。
的第二个参数IntegrationFlow.from()是一个Consumer<SourcePollingChannelAdapterSpec>lambda 的 lambda 允许您提供选项(例如PollerMetadata或SmartLifecycle) 的SourcePollingChannelAdapter.
以下示例演示如何使用 Fluent API 和 lambda 创建IntegrationFlow:
@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();
}
对于那些没有构建要求的情况Message对象,你可以使用IntegrationFlow.fromSupplier()基于java.util.function.Supplier.
结果Supplier.get()会自动包装在Message(如果它还不是Message).