在Spring JMS集成中配置基于时间间隔的cron

问题描述:

我需要在指定的时间间隔内将队列1中的消息转发到队列2,但不是仅在消息到达队列1后。以下是我的配置。在Spring JMS集成中配置基于时间间隔的cron

<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配置立即将消息转发从队列1到队列2,而无视< INT:轮询>配置。我已经尝试了基于间隔的和基于cron的解决方案,他们似乎工作相似(立即从Queue1到Queue2传递消息)。这里的“轮询器”配置有什么问题吗?任何帮助都感激不尽。

您需要适配器上的接收超时。否则,它会阻止receive()并立即获取消息。

编辑:请参阅下面的评论 - 线程轮询队列不再默认,自2.0.4以来的块。

您可能还想考虑为您的轮询器使用2.0+语法;您当前的语法是2.0弃用和2.1不准......

<jms:inbound-channel-adapter id="in" channel="jmsinToStdoutChannel" destination="requestQueue"> 
    <poller fixed-delay="30000"/> 
</jms:inbound-channel-adapter> 

只是为了澄清...如果接收超时设置在适配器上,轮询线程将阻塞,长期或直到消息到达。这可能使其看起来像轮询者不遵守其时间表。默认值(自2.0.4开始)是不会阻止这意味着只有在轮询时间表上才会收到消息。

+0

感谢您的回复。我尝试了您的建议,但没有解决问题。当我通过文档再次@ [链接](http://static.springsource.org/spring-integration/reference/htmlsingle/),它告诉我一些东西,这个功能不支持基于队列的适配器作为他们的接收是不是等待? **另一方面,当使用Spring Integration自己的基于队列的通道时,超时值确实有机会参与。以下示例演示howa Polling Consumer几乎会立即收到消息。** 您曾尝试过吗?再次感谢! – CoderTR 2012-03-10 04:14:44

+0

您使用的是什么版本的Spring集成? 行为在2.0.4中更改为默认情况下不执行阻止呼叫。 https://github.com/garyrussell/spring-integration/commit/b59bdc0d70087b015589a70ed3cb32ef44cf6dd6 – 2012-03-12 19:38:36

+0

当前的2.0.x版本是2.0.5;但2.1.0也可用。 – 2012-03-12 19:42:36