问题
I want to build a scheme with several outbound gateways, that could be added in runtime (lets say it starts with 2 gateways but have ability to add 3rd-4th in runtime). I want to have http-outbound-gateways for their functionality but wanna build their instances in runtime. The problem is in registering channels subscribed to these gateways in spring context. Atm I have 3 desicions and cant choose right one.
Register newely created channels to application context with
registerBeanDefinition("<my id>", definition)
or something similar. Not happy with this desicion cause would prefer not to have such rough access to already built context.Have predefined list of channels, and limit insertion of new outbound gateways with number of this predefined channels. Variant suits me since there's only few gateways planned and it seems quite safe for me, though not very neat.
Searching for solution, I found
org.springframework.integration.support.channel.BeanFactoryChannelResolver
withorg.springframework.integration.support.channel.HeaderChannelRegistry
that seems suitable for me to use with prototyped channel bean. (map names that i have to refs i require). However sinceorg.springframework.integration.support.channel.BeanFactoryChannelResolver
doesnt have public setter for this registry, im not sure i can use it safely, though i consider using own ChannelResolver for this needs.
What is the right way to solve this?
回答1:
See the dynamic-ftp sample application. It adds ftp outbound adapters using a child application context for each.
In effect, a dynamic router routes to the input channel for each adapter.
来源:https://stackoverflow.com/questions/23248987/runtime-configurable-dynamic-routing-in-spring-integration