在 Spring JMS 集成中配置基于间隔的 cron
我需要在指定的时间间隔内将消息从 Queue1 转发到 Queue2,但不是在消息到达 Queue1 后才转发。下面是我的配置。
<int-jms:inbound-channel-adapter id="inboundChannelAdapterId" connection-factory="connFactory" destination="jmsQueue1" channel="queueChannel" >
<int:poller send-timeout="2000" >
<!--
<int:interval-trigger initial-delay="60000" interval="60000"
fixed-rate="true"/>
-->
<int:cron-trigger expression="0 0/1 * * * ?" />
</int:poller>
</int-jms:inbound-channel-adapter>
<int-jms:outbound-channel-adapter channel="queueChannel" connection-factory="connFactory" destination="jmsQueue2" >
</int-jms:outbound-channel-adapter>
<int:channel id="queueChannel" />
上面的 xml 配置立即将消息从 Queue1 转发到 Queue2,忽略
I need to forward message from Queue1 to Queue2 in specified interval but NOT just after the message arrived in Queue1. Below is my config.
<int-jms:inbound-channel-adapter id="inboundChannelAdapterId" connection-factory="connFactory" destination="jmsQueue1" channel="queueChannel" >
<int:poller send-timeout="2000" >
<!--
<int:interval-trigger initial-delay="60000" interval="60000"
fixed-rate="true"/>
-->
<int:cron-trigger expression="0 0/1 * * * ?" />
</int:poller>
</int-jms:inbound-channel-adapter>
<int-jms:outbound-channel-adapter channel="queueChannel" connection-factory="connFactory" destination="jmsQueue2" >
</int-jms:outbound-channel-adapter>
<int:channel id="queueChannel" />
The above xml configuration forwards the message immediately from Queue1 to Queue2, disregarding <int:poller> configuration. I have tried both interval based and cron based solutions and they seem to work similar (delivering messages from Queue1 to Queue2 immediately). Is there anything wrong with the "poller" configuration here? Any help will be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要适配器上的接收超时。否则它将在 receive() 上阻塞并立即获取消息。编辑:请参阅下面的注释 - 从 2.0.4 开始,默认情况下轮询队列的线程不再阻塞。
您可能还需要考虑为您的轮询器使用 2.0+ 语法;您当前的语法在 2.0 中已弃用,并且在 2.1 中不允许...
只是为了澄清...如果在适配器上设置了接收超时,则轮询器线程将阻塞那么长时间或直到消息到达。这可能会让轮询器看起来没有遵守其时间表。默认值(自 2.0.4 起)是不阻塞,这意味着消息只会按照轮询器的时间表接收。
You need a receive-timeout on the adapter. Otherwise it will block on the receive() and immediately get the message.EDIT: See comments below - the thread polling the queue no longer blocks by default, since 2.0.4.
You may also want to consider using 2.0+ syntax for your poller; your current syntax was deprecated in 2.0 and not allowed in 2.1...
Just to clarify... if a receive-timeout is set on the adapter, the poller thread will block that long or until a message arrives. This may make it look like the poller is not obeying its schedule. The default (since 2.0.4) is to not block which means a message will be received only on the poller's schedule.