ゲートウェイとしての 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 名を取得します。@MessagingGateway.name()
属性またはオーバーロードされた IntegrationFlow.from(Class<?> serviceInterface, Consumer<GatewayProxySpec> endpointConfigurer)
ファクトリメソッドを使用して、その ID を変更できます。また、インターフェース上の @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;