3

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.

CoderTR
  • 500
  • 3
  • 7
  • 19

1 Answers1

2

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...

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

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • thanks for your reply. I tried your suggestion and doesn't fix the issue. When i was going thru the doc again @ [link](http://static.springsource.org/spring-integration/reference/htmlsingle/), it tells me something that this feature is not supported queue based adapter as their receive is not blocked wait?? **On the other hand when using Spring Integration's own queue-based channels, the timeout value does have a chance to participate. The following example demonstrates howa Polling Consumer will receive Messages nearly instantaneously.** Did you ever try this before ? thanks again! – CoderTR Mar 10 '12 at 04:14
  • What version of Spring Integration are you using? The behavior was changed in 2.0.4 to not do a blocking call by default. https://github.com/garyrussell/spring-integration/commit/b59bdc0d70087b015589a70ed3cb32ef44cf6dd6 – Gary Russell Mar 12 '12 at 19:38
  • The current 2.0.x version is 2.0.5; but 2.1.0 is available too. – Gary Russell Mar 12 '12 at 19:42
  • 1
    Yes, I was able to reproduce your issue by rolling back to 2.0.3. Everything works as expected with 2.0.5 and 2.1.0 - you don't need to add a receive-timeout to stop the thread from blocking on the receive(). – Gary Russell Mar 12 '12 at 19:54
  • Sorry. The down vote was an accidental click by me and I can't undo it now unless the answer is edited. – GeoGriffin Oct 31 '13 at 15:02
  • No problem - it's been a long time since I wrote this answer and had trouble parsing it myself :) - This prompted me to add a clarification. – Gary Russell Oct 31 '13 at 17:06