Spring Integration 5.5.18中<int:router>内<int:poller>配置报错及轮询方案咨询
问题
原本基于spring-integration 2.3.0.RELEASE开发的应用,<int:router>配置内嵌套<int:poller>可以正常运行,示例配置如下:
<int:router id="channelRouter" input-channel="exceptionChannel" expression="@system.getId(payload)"> <int:mapping value="0" channel="exceptionChannel0" /> <int:mapping value="1" channel="exceptionChannel1" /> <int:poller fixed-rate="10" task-executor="sysExecutor" /> </int:router> <task:executor id="sysExecutor" pool-size="1" queue-capacity="1" rejection-policy="DISCARD" />
升级到spring-integration 5.5.18后,出现XML解析错误,错误提示<int:poller>是无效内容,该错误在通过ClassPathXmlApplicationContext加载XML配置文件时触发,加载代码如下:
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class);
请问是否需要从<int:router>中移除<int:poller>?如果需要移除,没有poller时路由器该如何轮询输入通道?
回答
- 必须移除
<int:router>内部的<int:poller>配置。Spring Integration从3.0版本开始就调整了poller的配置规则,不再允许在路由器这类消息处理器内部直接配置poller,poller需要绑定到消息通道而不是处理器上。 - 移除后,要实现对输入通道的轮询,需要将poller配置到输入通道
exceptionChannel上,具体是把该通道定义为pollable-channel并附加poller配置:
<int:pollable-channel id="exceptionChannel"> <int:poller fixed-rate="10" task-executor="sysExecutor" /> </int:pollable-channel>
- 路由器本身只负责消息的路由逻辑,轮询动作由绑定到输入通道的poller来执行。当poller从
exceptionChannel拉取到消息后,会自动将消息交给路由器处理,完全能实现你原本的业务逻辑。
内容的提问来源于stack exchange,提问作者Mani kandan
相关产品推荐
相关产品推荐

