103.23. JPA ベースのべき等リポジトリーの使用
このセクションでは、デフォルトとして使用されるメモリー内ベースの代わりに、JPA ベースのべき等リポジトリーを使用します。
まず、クラス org.apache.camel.processor.idempotent.jpa.MessageProcessed
をモデルとして使用する必要がある META-INF/persistence.xml
に persistence-unit が必要です。
<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>
はい、#
構文オプションを使用して idempotentRepository
を使用して、ファイルコンシューマーエンドポイントで jpaStore Bean を参照する必要があります。
<route> <from uri="file://inbox?idempotent=true&idempotentRepository=#jpaStore"/> <to uri="bean:processInbox"/> </route>