入站通道适配器
通常,消息流从入站通道适配器(例如<int-jdbc:inbound-channel-adapter>
).
适配器配置了<poller>
,它会要求MessageSource<?>
定期生成消息。
Java DSL 允许启动IntegrationFlow
从MessageSource<?>
太。
为此,IntegrationFlow
Fluent API 提供了一个重载的IntegrationFlow.from(MessageSource<?> messageSource)
方法。
您可以配置MessageSource<?>
作为 Bean 提供,并将其作为该方法的参数提供。
第二个参数IntegrationFlow.from()
是一个Consumer<SourcePollingChannelAdapterSpec>
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
).