0
votes

I am trying to create a persistent event queue using 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).

I did an example version (without persisting with JPA), that do something similar to what I need:

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

My idea is to read the database every 5 seconds (configurable), and then process the elements in the "queue" recovered from database. 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.

1
Hi, what exceptions are you getting? Did you look at the JPA sample provided at: github.com/SpringSource/spring-integration-samples/tree/master/… ?Gunnar Hillert
Hi, I'm getting no exceptions, but the object are not being saved to database neither recovered from it (I manually added some). I tried the sample from SpringSource, but it just save to or list from database, but doesn't recover object doing polling, and send to a channel. In any case, I would prefer to use inbound-channel-adapter and outbound-channel-adapter before using gateways (according to documentation, this can be done with both systems).greuze

1 Answers

0
votes

I recently found out that queueChannels can become persistent with a Jdbc.

See http://docs.spring.io/spring-integration/reference/html/jdbc.html chapter Backing Message Channels