Spring Integration多通道复用同一Router的实现方案问询
解决方案:统一接入同一Router
当然可以!完全没必要为每个Channel重复声明相同的Router实例——你只需要把所有目标Channel对应的处理链输出,统一指向同一个Router的输入Channel即可,这样既精简了冗余配置,又能避免ApplicationContext变得混乱。
核心思路就是:将各个业务处理链的output-channel直接配置为Router所在的Channel,所有经过链处理后的消息会自动流转到这个Router中进行路由,无需为每个链单独创建Router实例。
以下是具体的配置示例:
<int:chain input-channel="channel-1" output-channel="router"> <int:service-activator ref="serviceA" method="doService" /> <int:service-activator ref="serviceB" method="doService" /> <int:service-activator ref="serviceC" method="doService" /> </int:chain> <int:chain input-channel="channel-2" output-channel="router"> <int:service-activator ref="serviceD" method="doService" /> <int:service-activator ref="serviceE" method="doService" /> <int:service-activator ref="serviceF" method="doService" /> </int:chain> <int:chain input-channel="router"> <int:router> <bean class="com.foo.MyClass" /> </int:router> </int:chain>
这样不管你有10个还是更多的Channel,只需要把对应处理链的output-channel设为router这个Channel,所有消息都会进入同一个Router实例进行路由处理,彻底消除了配置冗余。
内容的提问来源于stack exchange,提问作者Stempler
相关产品推荐
相关产品推荐

