如何使Spring集成的JDBC入站通道适配器轮询新数据?

huangapple go评论69阅读模式
英文:

How to make Spring Integrations jdbc inbound channel adapter to poll new data?

问题

我已经编写了如下的JDBC入站适配器:

int-jdbc:inbound-channel-adapter id="jdbcInbound"
                                      channel="channel"
                                      data-source="dataSource"
                                      query="SELECT * FROM Trade"
                                      row-mapper="TradeRowMapper"
                                      max-rows-per-poll="100">
        <int:poller fixed-delay="60000" time-unit="SECONDS"/>
</int-jdbc:inbound-channel-adapter>

这个工作正常。但是如果在整天内向Trade表中添加了新记录,新记录不会被检索。为了使其轮询新数据,需要进行哪些更改?这个适配器将在5个工作日(周一至周五)内保持运行,应该读取所有新记录。

英文:

I have written jdbc inbound adapter as below

int-jdbc:inbound-channel-adapter id=&quot;jdbcInbound&quot;
                                      channel=&quot;channel&quot;
                                      data-source=&quot;dataSource&quot;
                                      query=&quot;SELECT * FROM Trade&quot;
                                      row-mapper=&quot;TradeRowMapper&quot;
                                      max-rows-per-poll=&quot;100&quot;&gt;
        &lt;int:poller fixed-delay=&quot;60000&quot; time-unit=&quot;SECONDS&quot;/&gt;
    &lt;/int-jdbc:inbound-channel-adapter&gt;

This works fine.
But if new records are added to the Trade table say throughout the day, new records are not picked up. What changes do I need to make for it poll new data as well. This adapter is going to keep running for 5 business days monday-friday - and it should read all new records as well.

答案1

得分: 1

这在参考文档中有解释:

[...] 适配器还有一个UPDATE语句,用于标记记录为已处理,以便它们不会在下一次轮询中出现。

还有一个显示如何使用它的代码片段:

<int-jdbc:inbound-channel-adapter query="select * from item where status=2"
    channel="target" data-source="dataSource"
    update="update item set status=10 where id in (:id)" />
英文:

This is answered in the reference docs:

> [...] the adapter also has an UPDATE statement that marks the records as processed so that they do not show up in the next poll.

There is also a snippet showing how to use it:

&lt;int-jdbc:inbound-channel-adapter query=&quot;select * from item where status=2&quot;
    channel=&quot;target&quot; data-source=&quot;dataSource&quot;
    update=&quot;update item set status=10 where id in (:id)&quot; /&gt;

huangapple
  • 本文由 发表于 2023年2月8日 19:50:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定