简体   繁体   中英

Spring Integration JPA inbound channel adapter with transactional poller Java configuration

I am trying to use spring integrations jpa-inbound-channel-adapter to fetch records from a database and perform a set of operations on them. I also need to make sure that any given point of time my concurrently running instances does not get the same record more than once.

As I checked the documentation below is how a jpa-inbound-channel-adapter can be configured to handle transactions,

<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>

I have not found any way to achieve the same with Java configurations in a spring boot application (without xml configurations). I can see Java configuration examples but none of them with transactional. Any pointers will be helpful.

See the configuration for the test cases .

Just add .transactional() to the endpoint:

    @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();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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