0
votes

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.

1

1 Answers

1
votes

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