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
获取约定的 bean 名称,例如[FLOW_BEAN_NAME.gateway]
.
您可以使用@MessagingGateway.name()
属性或重载的IntegrationFlow.from(Class<?> serviceInterface, Consumer<GatewayProxySpec> endpointConfigurer)
Factory 方法。
此外,来自@MessagingGateway
注解应用于目标GatewayProxyFactoryBean
.
当 annotation 配置不适用时,Consumer<GatewayProxySpec>
variant 可用于为目标代理提供适当的选项。
此 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;