受信チャネルアダプター

通常、メッセージフローは受信チャネルアダプター ( <int-jdbc:inbound-channel-adapter> など) から開始します。アダプターは <poller> で構成され、定期的にメッセージを生成するように MessageSource<?> に要求します。Java DSL では、MessageSource<?> から IntegrationFlow を開始することもできます。この目的のために、IntegrationFlow fluent API はオーバーロードされた IntegrationFlow.from(MessageSource<?> messageSource) メソッドを提供します。MessageSource<?> を Bean として構成し、それをそのメソッドの引数として提供できます。IntegrationFlow.from() の 2 番目のパラメーターは、SourcePollingChannelAdapter のオプション ( PollerMetadata または SmartLifecycle など) を提供できる Consumer<SourcePollingChannelAdapterSpec> ラムダです。次の例は、流れるような API とラムダを使用して 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 オブジェクトを直接構築する必要がない場合は、java.util.function.Supplier に基づく IntegrationFlow.fromSupplier() バリアントを使用できます。Supplier.get() の結果は、自動的に Message にラップされます(まだ Message でない場合)。