简体   繁体   English

使用Spring Integration的JPA队列

[英]JPA queue using Spring Integration

I am trying to create a persistent event queue using Spring Integration. 我正在尝试使用Spring Integration创建一个持久事件队列。 In a first version I want to use JPA (with a MySQL database), and in the future it is very possible to migrate to a JMS version (I want the transition to be so easy as possible). 在第一个版本中,我想使用JPA(与MySQL数据库一起使用),并且将来很有可能迁移到JMS版本(我希望转换尽可能容易)。

I did an example version (without persisting with JPA), that do something similar to what I need: 我做了一个示例版本(无需坚持使用JPA),该版本与我需要执行的操作类似:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int="http://www.springframework.org/schema/integration"
       xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/beans">

    <int:channel id="customerEventChannel">
        <int:queue/>
    </int:channel>

    <bean id="customerEventService" class="springintegration.CustomerEventService"/>

    <int:outbound-channel-adapter ref="customerEventService" method="handleCustomerEvent" channel="customerEventChannel">
        <int:poller fixed-delay="3000" max-messages-per-poll="1" />
    </int:outbound-channel-adapter>

</beans>

But when I try to modify the example to use JPA inbound and outbound channel adapters, I cannot make it work. 但是,当我尝试修改示例以使用JPA入站和出站通道适配器时,我无法使其工作。

My idea is to read the database every 5 seconds (configurable), and then process the elements in the "queue" recovered from database. 我的想法是每5秒钟读取一次数据库(可配置),然后处理从数据库中恢复的“队列”中的元素。 On the other hand, I want to insert new elements in the database calling a method in a service class. 另一方面,我想在数据库中插入新元素,以在服务类中调用方法。 For doing this, I tried: 为此,我尝试:

    <int:channel id="customerEventInputChannel" />
    <int:channel id="customerEventOutputChannel" />

        <int-jpa:inbound-channel-adapter channel="customerEventInputChannel"
                                         entity-class="springintegration.CustomerEvent"
                                         entity-manager-factory="entityManagerFactory"
                                         auto-startup="true"
                                         expect-single-result="true"
                                         delete-after-poll="true">

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

        <int-jpa:outbound-channel-adapter channel="customerEventOutputChannel"
                                          entity-class="springintegration.CustomerEvent"
                                          entity-manager-factory="entityManagerFactory">
            <int-jpa:transactional transaction-manager="transactionManager" />
        </int-jpa:outbound-channel-adapter>

But I am missing something because I cannot read or write to database. 但是我丢失了一些东西,因为我无法读取或写入数据库。 I tried also with service-activator, bridge, gateway, etc., with same results. 我也尝试过使用服务激活器,网桥,网关等,但结果相同。

Any help would be appreciated. 任何帮助,将不胜感激。

I recently found out that queueChannels can become persistent with a Jdbc. 我最近发现,queueChannels可以与Jdbc保持一致。

See http://docs.spring.io/spring-integration/reference/html/jdbc.html chapter Backing Message Channels 请参阅http://docs.spring.io/spring-integration/reference/html/jdbc.html一章“ 备份消息通道”

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

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