【问题标题】:Spring Integration JPA inbound channel adapter with transactional poller Java configuration具有事务轮询器 Java 配置的 Spring Integration JPA 入站通道适配器
【发布时间】:2019-12-04 09:49:53
【问题描述】:

我正在尝试使用 spring integrations 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 配置示例,但没有一个是事务性的。任何指针都会有所帮助。

【问题讨论】:

    标签: java spring-boot spring-data-jpa spring-integration


    【解决方案1】:

    the configuration for the test cases

    只需将.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();
        }
    

    【讨论】:

      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 2019-02-19
      • 2012-11-03
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多