我有几个渠道的Spring集成项目。我希望一些通道输出将发送到同一路由器。
例如,对于通道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>无需声明多个路由器
发布于 2019-01-30 22:32:12
目前还没有;但是我们有一个开放的enhancement request。
也就是说,为什么需要声明多个路由器?只需声明一个并将每个链的输出通道设置为其输入通道即可。
https://stackoverflow.com/questions/54441550
复制相似问题