182.16. JPA ベースのべき等リポジトリーの使用


EIP パターン の Idempotent Consumer は、重複するメッセージを除外するために使用されます。JPA ベースのべき等リポジトリーが提供されます。

JPA ベースのべき等リポジトリーを使用するには。

手順

  1. persistence.xml ファイルで persistence-unit を設定します。
  2. org.apache.camel.processor.idempotent.jpa.JpaMessageIdRepository で使用される org.springframework.orm.jpa.JpaTemplate を設定します。
  3. エラー形式のマクロを設定します: snippet: java.lang.IndexOutOfBoundsException: Index: 20、Size: 20
  4. べき等リポジトリーを設定します: org.apache.camel.processor.idempotent.jpa.JpaMessageIdRepository :
  5. Spring XML ファイルに JPA べき等リポジトリーを作成します。
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route id="JpaMessageIdRepositoryTest">
        <from uri="direct:start" />
        <idempotentConsumer messageIdRepositoryRef="jpaStore">
            <header>messageId</header>
            <to uri="mock:result" />
        </idempotentConsumer>
    </route>
</camelContext>

IDE 内でこの Camel コンポーネントテストを実行する場合

このコンポーネントのテスト を、Maven を介さずに IDE 内で直接実行すると、次のような例外が発生する可能性があります。

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is
<openjpa-2.2.1-r422266:1396819 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization,
but the following listed types were not enhanced at build time or at class load time with a javaagent: "org.apache.camel.examples.SendEmail".
    at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
    at org.apache.camel.processor.jpa.JpaRouteTest.cleanupRepository(JpaRouteTest.java:96)
    at org.apache.camel.processor.jpa.JpaRouteTest.createCamelContext(JpaRouteTest.java:67)
    at org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:238)
    at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:208)

ここでの問題は、ソースが Maven ではなく IDE を介してコンパイルまたは再コンパイルされていることです。これにより、ビルド時にバイトコードが拡張 されます。これを克服するには、OpenJPA の動的バイトコード拡張 を有効にする必要があります。たとえば、Camel で使用されている現在の OpenJPA のバージョンが 2.2.1 であるとすると、IDE 内でテストを実行するには、次の引数を JVM に渡す必要があります。

-javaagent:<path_to_your_local_m2_cache>/org/apache/openjpa/openjpa/2.2.1/openjpa-2.2.1.jar
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.