103.23. JPA 기반 멱등 리포지토리 사용
이 섹션에서는 기본값으로 사용되는 메모리 내 기반 대신 JPA 기반 멱등 리포지토리를 사용합니다.
먼저 META-INF/persistence.xml 에 persistence-unit이 필요합니다. 여기서는 클래스 org.apache.camel.processor.idempotent.jpa.MessageProcessed 를 모델로 사용해야 합니다.
<persistence-unit name="idempotentDb" transaction-type="RESOURCE_LOCAL">
<class>org.apache.camel.processor.idempotent.jpa.MessageProcessed</class>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:derby:target/idempotentTest;create=true"/>
<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
<property name="openjpa.Multithreaded" value="true"/>
</properties>
</persistence-unit>그런 다음 Spring XML 파일에 JPA 멱등 리포지토리를 생성할 수 있습니다.
<!-- we define our jpa based idempotent repository we want to use in the file consumer -->
<bean id="jpaStore" class="org.apache.camel.processor.idempotent.jpa.JpaMessageIdRepository">
<!-- Here we refer to the entityManagerFactory -->
<constructor-arg index="0" ref="entityManagerFactory"/>
<!-- This 2nd parameter is the name (= a category name).
You can have different repositories with different names -->
<constructor-arg index="1" value="FileConsumer"/>
</bean>
그리고 예, # 구문 옵션을 사용하여 멱등 Repository 을 사용하여 파일 소비자 끝점에서 jpaStore 빈을 참조해야합니다.
<route> <from uri="file://inbox?idempotent=true&idempotentRepository=#jpaStore"/> <to uri="bean:processInbox"/> </route>