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.