簡體   English   中英

具有事務輪詢器Java配置的Spring Integration JPA入站通道適配器

[英]Spring Integration JPA inbound channel adapter with transactional poller Java configuration

我正在嘗試使用spring集成jpa-inbound-channel-adapter從數據庫中獲取記錄,並對它們執行一組操作。 我還需要確保並發運行的實例在任何給定的時間點都不會多次獲得相同的記錄。

當我查看以下文檔時,如何配置jpa-inbound-channel-adapter來處理事務,

<int-jpa:inbound-channel-adapter
    channel="inboundChannelAdapterOne"
    entity-manager="em"
    auto-startup="true"
    jpa-query="select s from Student s"
    expect-single-result="true"
    delete-after-poll="true">
    <int:poller fixed-rate="2000" >
        <int:transactional propagation="REQUIRED"
            transaction-manager="transactionManager"/>
    </int:poller>
</int-jpa:inbound-channel-adapter>

我還沒有找到在Spring Boot應用程序中使用Java配置(沒有xml配置)實現相同目的的任何方法。 我可以看到Java配置示例,但沒有一個帶有事務性。 任何指針都會有所幫助。

請參閱測試用例的配置

只需將.transactional()添加到端點:

    @Bean
    public IntegrationFlow pollingAdapterFlow(EntityManagerFactory entityManagerFactory) {
        return IntegrationFlows
                .from(Jpa.inboundAdapter(entityManagerFactory)
                                .entityClass(StudentDomain.class)
                                .maxResults(1)
                                .expectSingleResult(true),
                        e -> e.poller(p -> p.trigger(new OnlyOnceTrigger())
                                .transactional()))
                .channel(c -> c.queue("pollingResults"))
                .get();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM