繁体   English   中英

Spring Integration消息轮询

[英]Spring Integration message polling

我有一个用于从数据库队列中轮询消息的Spring配置设置:

<int:annotation-config default-publisher-channel="messageChannel" />

<task:executor id="messageTaskExecutor" pool-size="1"
    queue-capacity="1" rejection-policy="CALLER_RUNS" />

<int:transaction-synchronization-factory id="syncFactory">
    <int:after-commit expression="@messageSessionStore.removeFromIdCache(headers.id.toString())" />
    <int:after-rollback expression="@messageSessionStore.removeFromIdCache(headers.id.toString())" />
</int:transaction-synchronization-factory>

<bean id="messageQueryProvider"
    class="org.springframework.integration.jdbc.store.channel.OracleChannelMessageStoreQueryProvider" />

<bean id="messageSessionStore"
    class="org.springframework.integration.jdbc.store.JdbcChannelMessageStore">
    <property name="dataSource" ref="dataSource" />
    <property name="channelMessageStoreQueryProvider" ref="messageQueryProvider" />
    <property name="tablePrefix" value="QUEUE_" />
    <property name="usingIdCache" value="true" />
</bean>

<int:channel id="messageChannel">
    <int:queue message-store="messageSessionStore" />
</int:channel>

<int:poller id="defaultPoller" fixed-delay="500" max-messages-per-poll="1" task-executor="messageTaskExecutor" default="true">
    <int:transactional propagation="REQUIRED" synchronization-factory="syncFactory" isolation="READ_COMMITTED" transaction-manager="eosTransactionManager"/>
</int:poller>

但是,该应用程序在多个节点上运行。 重新启动服务器时,似乎发生了消息被多个节点拾取的情况(所有节点都立即关闭并按顺序重新启动)。 有什么办法可以避免多重消息处理?

使用OracleChannelMessageStoreQueryProvider不可能以某种方式实现。 仅仅因为我们依赖FOR UPDATE SKIP LOCKED 因此,当一个节点执行SELECT时,记录将被锁定,下一个记录将转到表中的下一个空闲行。

JavaDoc中没有setUsingIdCache()

 * <p>If using the provided {@link OracleChannelMessageStoreQueryProvider}, don't set {@link #usingIdCache}
 * to true, as the Oracle query will ignore locked rows.</p>

但我认为这完全无关。 删除该选项和<int:transaction-synchronization-factory>将简化您的配置,但是不能更改其行为。

我认为您看到的就像round-robin :一个节点获得第一行,下一节点跳过它并获得下一行。

我以某种方式不相信使用Oracle时,不同的节点会收到相同的消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM