Spring integration 抽象出站网关实现的最佳方法
我的spring integration应用程序需要能够通过简单的配置更改在Kafka和旧式消息传递库(tibco rendezvous,spring integration不提供任何默认出站网关实现)之间按需切换。Spring integration 抽象出站网关实现的最佳方法,spring-integration,Spring Integration,我的spring integration应用程序需要能够通过简单的配置更改在Kafka和旧式消息传递库(tibco rendezvous,spring integration不提供任何默认出站网关实现)之间按需切换。 遗留消息传递库提供了一些基本的请求/回复方法 Class LegacyTransport { Object request(Object query,String topic); } 我正在尝试找出抽象出站消息网关(Kafka和legacy)的最佳方法,以便在主Integ
遗留消息传递库提供了一些基本的请求/回复方法
Class LegacyTransport {
Object request(Object query,String topic);
}
我正在尝试找出抽象出站消息网关(Kafka和legacy)的最佳方法,以便在主IntegrationFlow中(通过简单的配置更改)交换其中一个
我目前的想法是使用以下方法作为我的主要集成流程的一部分:
IntegrationFlowDefinition.gateway(IntegrationFlow flow)
@Bean
public IntegrationFlow mainFlow(Function<String,IntegrationFlow> gatewaySubflowFactory)
return IntegrationFlows.from(INPUT_CHANNEL)
...
[do some useful processing here]
...
.gateway(gatewaySubflowFactory.apply("some_topic"))
...
[do more useful stuff with gateway output here]
...
.get()
首先创建两个具有相同名称的条件子流工厂bean,包装每个消息传递网关:
@ConditionalOnProperty(name="messaging",havingValue=[TIBCO/KAFKA])
@Bean
Function<String,IntegrationFlow> gatewaySubflowFactory() {
return (String topic) -> ((IntegrationFlowDefinition<?> f) ->
f.handle(
[messaging library specific implementation here]
));
}
@conditionalnproperty(name=“messaging”,havingValue=[TIBCO/KAFKA])
@豆子
函数网关子流工厂(){
返回(字符串主题)->(集成流定义f)->
f、 处理(
[此处为特定于消息传递库的实现]
));
}
然后在我的主集成流中使用该bean:
IntegrationFlowDefinition.gateway(IntegrationFlow flow)
@Bean
public IntegrationFlow mainFlow(Function<String,IntegrationFlow> gatewaySubflowFactory)
return IntegrationFlows.from(INPUT_CHANNEL)
...
[do some useful processing here]
...
.gateway(gatewaySubflowFactory.apply("some_topic"))
...
[do more useful stuff with gateway output here]
...
.get()
@Bean
公共集成流主流(功能网关子流工厂)
返回IntegrationFlows.from(输入通道)
...
[在此进行一些有用的处理]
...
.gateway(gatewaySubflowFactory.apply(“某些主题”))
...
[在此处使用网关输出执行更多有用的操作]
...
.get()
有更好(更简单)的方法吗?提前感谢您的专业知识、想法和时间。
最好的祝愿任何出站网关都只是更通用的服务激活器模式的特定实现。因此,您的
LegacyTransport.request()
可以包装到服务激活器配置中。这是第一次
第二:别忘了。永远不要忘记。Spring集成中的第一类citizen之一是一个MessageChannel
抽象:常规服务激活器,Kafka的特定出站网关-无所谓与它们交互的主要点是为端点输入配置的消息通道
因此,您的卡夫卡流和Tibco流都可以从同一个通道开始。您的主流只是将其输出发送到该通道。有关更多信息,请参见IntegrationFlowDefinition.channel()
这两个特定的流都可以用@ConditionalOnProperty
标记,以避免它们在运行时同时出现
总结我的推理,以下是一些配置抓痕:
@Bean
public IntegrationFlow mainFlow() {
return IntegrationFlows.from(INPUT_CHANNEL)
...
[do some useful processing here]
...
.gateway(OUTBOUND_GATEWAY_CHANNEL)
...
[do more useful stuff with gateway output here]
...
.get()
}
@ConditionalOnProperty(name="messaging",havingValue=KAFKA)
@Bean
public IntegrationFlow kafkaFlow() {
return IntegrationFlows.from(OUTBOUND_GATEWAY_CHANNEL)
.handle(Kafka.outboundGateway())
.get();
}
@ConditionalOnProperty(name="messaging",havingValue=TIBCO)
@Bean
public IntegrationFlow tibcoFlow() {
return IntegrationFlows.from(OUTBOUND_GATEWAY_CHANNEL)
.handle(legacyTransport, "request")
.get();
}
任何出站网关都只是更通用的服务激活器模式的特定实现。因此,您的
LegacyTransport.request()
可以包装到服务激活器配置中。这是第一次
第二:别忘了。永远不要忘记。Spring集成中的第一类citizen之一是一个MessageChannel
抽象:常规服务激活器,Kafka的特定出站网关-无所谓与它们交互的主要点是为端点输入配置的消息通道
因此,您的卡夫卡流和Tibco流都可以从同一个通道开始。您的主流只是将其输出发送到该通道。有关更多信息,请参见IntegrationFlowDefinition.channel()
这两个特定的流都可以用@ConditionalOnProperty
标记,以避免它们在运行时同时出现
总结我的推理,以下是一些配置抓痕:
@Bean
public IntegrationFlow mainFlow() {
return IntegrationFlows.from(INPUT_CHANNEL)
...
[do some useful processing here]
...
.gateway(OUTBOUND_GATEWAY_CHANNEL)
...
[do more useful stuff with gateway output here]
...
.get()
}
@ConditionalOnProperty(name="messaging",havingValue=KAFKA)
@Bean
public IntegrationFlow kafkaFlow() {
return IntegrationFlows.from(OUTBOUND_GATEWAY_CHANNEL)
.handle(Kafka.outboundGateway())
.get();
}
@ConditionalOnProperty(name="messaging",havingValue=TIBCO)
@Bean
public IntegrationFlow tibcoFlow() {
return IntegrationFlows.from(OUTBOUND_GATEWAY_CHANNEL)
.handle(legacyTransport, "request")
.get();
}
像往常一样完美!:-)。。。再次感谢你的知识和时间,阿泰姆!!像往常一样完美!:-)。。。再次感谢你的知识和时间,阿泰姆!!