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

发布于 2025-01-02 05:21:10 字数 927 浏览 2 评论 0原文

我需要在指定的时间间隔内将消息从 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,忽略。配置。我尝试过基于间隔和基于 cron 的解决方案,它们的工作原理似乎相似(立即将消息从 Queue1 传递到 Queue2)。这里的“poller”配置有什么问题吗?任何帮助将不胜感激。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2025-01-09 05:21:10

您需要适配器上的接收超时。否则它将在 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 起)是不阻塞,这意味着消息只会按照轮询器的时间表接收。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文