My spring-integration app needs to be able to switch on demand between Kafka and a legacy messaging library (tibco rendezvous, for which spring-integration doesn't provide any default outbound gateway implementation) through a simple config change.
The legacy messaging library provides some basic request/reply method
Class LegacyTransport {
Object request(Object query,String topic);
}
I'm trying to find out what is the best way to abstract both messaging outbound gateways (Kafka and legacy) so that I can swap one for the other inside my main IntegrationFlow (through a simple config change).
My current idea is to use below method as part of my main IntegrationFlow:
IntegrationFlowDefinition.gateway(IntegrationFlow flow)
First create 2 conditional subflow factory beans with the same name wrapping each of my messaging gateways:
@ConditionalOnProperty(name="messaging",havingValue=[TIBCO/KAFKA])
@Bean
Function<String,IntegrationFlow> gatewaySubflowFactory() {
return (String topic) -> ((IntegrationFlowDefinition<?> f) ->
f.handle(
[messaging library specific implementation here]
));
}
Then use that bean in my main IntegrationFlow:
@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()
Is there any better (simpler?) way ?
Thanks a lot in advance for your expertise, your ideas and your time.
Best Regards