简体   繁体   English

Spring Integration JPA入站通道适配器

[英]Spring Integration JPA inbound channel adapter

I have a spring-integration message channel which read from a database using a jpa inbound-channel-adapter . 我有一个spring-integration message channel ,该message channel使用jpa inbound-channel-adapter从数据库中读取。

<int:channel id="logChannel">
    <int:priority-queue capacity="20" />
</int:channel>

<int-jpa:inbound-channel-adapter
    channel="logChannel" entity-class="com.objects.Transactionlog"
    entity-manager-factory="entityManagerFactory" auto-startup="true"
    jpa-query="SELECT x FROM Transactionlog AS x WHERE x.status LIKE '1'" max-results="1">
    <int:poller fixed-rate="5000">
        <int:transactional propagation="REQUIRED"
            transaction-manager="transactionManager" />
    </int:poller>
</int-jpa:inbound-channel-adapter>

This always reads only the first row of the table transactionlog . 这总是只读取表transactionlog的第一行。 So I want to update the status of each database entry just after read. 因此,我想在读取后立即更新每个数据库条目的status Any body know how to do that? 任何人都知道该怎么做吗?

If max-results="1" is OK for you and receive only one entity per 5 second is appropiate for your use-case, let it be. 如果max-results="1"对您来说还可以,并且每5秒仅收到一个实体适合您的用例,那就顺其自然。

Now how to update that entity to skip it on the next poll. 现在,如何更新该实体以在下一次轮询时跳过它。

The <int-jpa:inbound-channel-adapter> has delete-after-poll="true" option, which allows to perform entityManager.remove(entity) after an entity retrival. <int-jpa:inbound-channel-adapter>具有delete-after-poll="true"选项,该选项允许在entityManager.remove(entity)后执行entityManager.remove(entity)

Right, it is the real removal from DB. 正确,这是从数据库中真正删除的内容。 To convert it to the UPDATE, you can mark your entity with: 要将其转换为UPDATE,可以用以下方式标记您的实体:

@SQLDelete(sql = "UPDATE Transactionlog SET status = false WHERE id = ?")

Or something similar, that is appropiate for you. 或类似的东西,适合您。

Another feature is Transaction Synchronization , when you mark your <poller> with some before-commit factory and do UPDATE there. 另一个功能是事务同步 ,当您用一些before-commit工厂标记<poller>before-commit那里进行UPDATE时。 Something like: 就像是:

<int-jpa:inbound-channel-adapter ...>
    <int:poller fixed-rate="5000">
      <int:transactional propagation="REQUIRED"
           transaction-manager="transactionManager"
           synchronization-factory="txSyncFactory" />
    </int:poller>
<int-jpa:inbound-channel-adapter>

<int:transaction-synchronization-factory id="txSyncFactory">
    <int:before-commit channel="updateEntityChannel" />
</int:transaction-synchronization-factory>

<int:chain input-channel="updateEntityChannel">
   <int:enricher>
       <int:property name="status" value="true"/>
   </int:enricher>
   <int-jpa:outbound-channel-adapter entity-manager="entityManager"/>
</int:chain/>

Something like that. 这样的事情。

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

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