我正在尝试使用 Spring Integration 创建一个持久事件队列。在第一个版本中,我想使用 JPA(带有 MySQL 数据库),并且将来很有可能迁移到 JMS 版本(我希望过渡尽可能简单)。
我做了一个示例版本(没有坚持使用 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>
但是当我尝试修改示例以使用 JPA 入站和出站通道适配器时,我无法使其工作。
我的想法是每 5 秒读取一次数据库(可配置),然后处理从数据库中恢复的“队列”中的元素。另一方面,我想在数据库中插入新元素,调用服务类中的方法。为此,我尝试了:
<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>
但我错过了一些东西,因为我无法读取或写入数据库。我也尝试了服务激活器、网桥、网关等,结果相同。
任何帮助,将不胜感激。