【发布时间】:2019-02-06 21:52:43
【问题描述】:
我有多个渠道的 Spring Integration 项目。我希望某些通道输出会到同一个路由器。
例如,对于通道 1,我有:
<int:chain input-channel="channel-1" output-channel="channel-1-out>
<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-1-out">
<int:router>
<bean class="com.foo.MyClass" />
</int:router>
</int:chain>
对于通道 2,我必须复制路由器类:
<int:chain input-channel="channel-2" output-channel="channel-2-out>
<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="channel-2-out">
<int:router>
<bean class="com.foo.MyClass" />
</int:router>
</int:chain>
问题在于,对于 10 个不同的通道,我必须编写 10 个不同的路由器,它们都指向同一个路由器类。对我来说,这似乎有点乏味和多余,而且它使 ApplicationContext 变得混乱。
有没有办法简单地将想要的输出添加到同一个路由器?类似的东西
<int:chain input-channel=
"channel-1-out" +
"channel-2-out" +
"channel-3-out"....>
<int:router>
<bean class="com.foo.MyClass" />
</int:router>
</int:chain>
编辑:
简单的解决方案,将每条链的输出通道设置为路由器输入通道。
<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>
无需声明多个路由器
【问题讨论】: