ゲートウェイとしての IntegrationFlow 

IntegrationFlow は、次の例に示すように、GatewayProxyFactoryBean コンポーネントを提供するサービスインターフェースから開始できます。

public interface ControlBusGateway {

    void send(String command);
}

...

@Bean
public IntegrationFlow controlBusFlow() {
    return IntegrationFlow.from(ControlBusGateway.class)
            .controlBus()
            .get();
}

インターフェースメソッドのすべてのプロキシには、IntegrationFlow 内の次の統合コンポーネントにメッセージを送信するためのチャネルが提供されます。サービスインターフェースに @MessagingGateway アノテーションを、メソッドに @Gateway アノテーションを付与できます。ただし、requestChannel は無視され、IntegrationFlow 内の次のコンポーネント用の内部チャネルにオーバーライドされます。そうでなければ、IntegrationFlow を使用してこのような構成を作成しても意味がありません。

デフォルトでは、GatewayProxyFactoryBean は [FLOW_BEAN_NAME.gateway] のような慣例的な Bean 名を取得します。この ID は、@MessagingGateway.name() 属性またはオーバーロードされた IntegrationFlow.from(Class<?> serviceInterface, Consumer<GatewayProxySpec> endpointConfigurer) ファクトリメソッドを使用して変更できます。また、インターフェースの @MessagingGateway アノテーションのすべての属性が、ターゲットの GatewayProxyFactoryBean に適用されます。アノテーション設定が適用できない場合は、Consumer<GatewayProxySpec> バリアントを使用して、ターゲットプロキシに適切なオプションを提供できます。この DSL メソッドは、バージョン 5.2 以降で利用可能です。

Java 8 では、次の例に示すように、java.util.function インターフェースを使用して統合ゲートウェイを作成することもできます。

@Bean
public IntegrationFlow errorRecovererFlow() {
    return IntegrationFlow.from(Function.class, (gateway) -> gateway.beanName("errorRecovererFunction"))
            .<Object>handle((p, h) -> {
                throw new RuntimeException("intentional");
            }, e -> e.advice(retryAdvice()))
            .get();
}

その errorRecovererFlow は次のように使用できます。

@Autowired
@Qualifier("errorRecovererFunction")
private Function<String, String> errorRecovererFlowGateway;