Configure interval based cron in Spring JMS integration

2k views Asked by At

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.

1

There are 1 answers

6
Gary Russell On

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.