第8章 Atom


Atom コンポーネント

atom: コンポーネントは、atom フィードのポーリングに使用されます。
Apache Camel は、デフォルトで 500 ミリ秒ごとにフィードをポーリングします。注記: コンポーネントは現在、ポーリング(かかる)フィードのみをサポートします。
Maven ユーザーは、このコンポーネントの pom.xml に以下の依存関係を追加する必要があります。
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-atom</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
Copy to Clipboard Toggle word wrap

URI 形式

atom://atomUri[?options]
Copy to Clipboard Toggle word wrap
ここでの atomUri は、ポーリングする Atom フィードへの URI です。

オプション

Expand
プロパティー デフォルト 説明
splitEntries true true の場合、Apache Camel はフィードをポーリングし、後続のポーリングではポーリングごとに各エントリーが返されます。フィードに 7 エントリーが含まれる場合、Apache Camel は最初のポーリングの最初のエントリー(次のポーリング上の 2 番目のエントリー)を返します。Apache Camel はフィードで新しい更新を行うエントリーがありません。false の場合、Apache Camel は呼び出しごとに新しいフィードをポーリングします。
filter true は、エントリーを返すようにフィルターするために分割されたエントリーでのみ使用されます。Apache Camel はデフォルトで、フィードから新しいエントリーのみを返す UpdateDateFilter を使用します。したがって、フィードから消費するクライアントは、同じエントリーを複数回受け取ることはありません。フィルターは最新の最後のエントリーを返します。
lastUpdate null 選択開始タイムスタンプとしてフィルターによってのみ使用されます( entry.updated タイムスタンプを使用します)。構文の形式は yyyy-MM-ddTHH:MM:ss です。例: 2007-12-24T17:45:59
throttleEntries true camel 2.5: 単一のフィードポーリングで特定されたすべてのエントリーを即座に配信するかどうかを設定します。true の場合、consumer.delay ごとに 1 つのエントリーのみが処理されます。splitEntriestrue に設定されている場合にのみ適用されます。
feedHeader true Abdera Feed オブジェクトをヘッダーとして追加するかどうかを設定します。
sortEntries false splitEntriestrue の場合、これらのエントリーを更新された日付でソートするかどうかを設定します。
consumer.delay 500 各ポーリングの遅延(ミリ秒単位)。
consumer.initialDelay 1000 ポーリングを開始する前にミリス。
consumer.userFixedDelay false true の場合は、プール間の固定遅延を使用します。そうでない場合は、固定レートが使用されます。詳細は、JDK の ScheduledExecutorService を参照してください。
username HTTP フィードからポーリングする場合の基本認証の場合。
password HTTP フィードからポーリングする場合の基本認証の場合。
URI にクエリーオプションは ?option=value&option=value&.. の形式で追加できます。

Camel on EAP デプロイメント

このコンポーネントは、Red Hat JBoss Enterprise Application Platform (JBoss EAP) コンテナー上で簡素化されたデプロイメントモデルを提供する Camel on EAP (Wildfly Camel) フレームワークによってサポートされます。このモデルの詳細は、Deploying into a Web Server の Apache Camel on JBoss EAP の章を参照してください

エクスチェンジデータ形式

Apache Camel は、エントリーを使用して返された エクスチェンジ に In ボディーを設定します。splitEntries フラグに応じて、Apache Camel は Entry または List<Entry> を返します
Expand
オプション 動作
splitEntries true 現在処理中のフィードからのエントリーを 1 つだけ設定します: exchange.in.body (Entry)
splitEntries false フィードのエントリー一覧全体が設定されます: exchange.in.body (List<Entry>)
Apache Camel は in ヘッダーに Feed オブジェクトを設定できます( feedHeader オプションを参照)。これを無効にします。

メッセージヘッダー

Apache Camel atom はこれらのヘッダーを使用します。
Expand
ヘッダー 説明
CamelAtomFeed Apache Camel 2.0: org.apache.abdera.model.Feed オブジェクトを使用する場合は、このヘッダーに設定されます。

サンプル

以下の例では、James Strachan のブログをポーリングしています。
from("atom://http://macstrac.blogspot.com/feeds/posts/default").to("seda:feeds");
Copy to Clipboard Toggle word wrap
この例では、SEDA キューに適したブログのみをフィルターリングしたいです。この例は、コンテナーで実行されていない、または Spring を使用して Apache Camel スタンドアロンを設定する方法も示しています。
@Override
protected CamelContext createCamelContext() throws Exception {
    // First we register a blog service in our bean registry
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("blogService", new BlogService());

    // Then we create the camel context with our bean registry
    context = new DefaultCamelContext(registry);

    // Then we add all the routes we need using the route builder DSL syntax
    context.addRoutes(createMyRoutes());

    // And finally we must start Camel to let the magic routing begins
    context.start();

    return context;
}

/**
 * This is the route builder where we create our routes using the Camel DSL syntax
 */
protected RouteBuilder createMyRoutes() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // We pool the atom feeds from the source for further processing in the seda queue
            // we set the delay to 1 second for each pool.
            // Using splitEntries=true will during polling only fetch one Atom Entry at any given time.
            // As the feed.atom file contains 7 entries, using this will require 7 polls to fetch the entire
            // content. When Camel have reach the end of entries it will refresh the atom feed from URI source
            // and restart - but as Camel by default uses the UpdatedDateFilter it will only deliver new
            // blog entries to "seda:feeds". So only when James Strachan updates his blog with a new entry
            // Camel will create an exchange for the seda:feeds.
            from("atom:file:src/test/data/feed.atom?splitEntries=true&consumer.delay=1000").to("seda:feeds");

            // From the feeds we filter each blot entry by using our blog service class
            from("seda:feeds").filter().method("blogService", "isGoodBlog").to("seda:goodBlogs");

            // And the good blogs is moved to a mock queue as this sample is also used for unit testing
            // this is one of the strengths in Camel that you can also use the mock endpoint for your
            // unit tests
            from("seda:goodBlogs").to("mock:result");
        }
    };
}

/**
 * This is the actual junit test method that does the assertion that our routes is working
 * as expected
 */
@Test
public void testFiltering() throws Exception {
    // create and start Camel
    context = createCamelContext();
    context.start();

    // Get the mock endpoint
    MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);

    // There should be at least two good blog entries from the feed
    mock.expectedMinimumMessageCount(2);

    // Asserts that the above expectations is true, will throw assertions exception if it failed
    // Camel will default wait max 20 seconds for the assertions to be true, if the conditions
    // is true sooner Camel will continue
    mock.assertIsSatisfied();

    // stop Camel after use
    context.stop();
}

/**
 * Services for blogs
 */
public class BlogService {

    /**
     * Tests the blogs if its a good blog entry or not
     */
    public boolean isGoodBlog(Exchange exchange) {
        Entry entry = exchange.getIn().getBody(Entry.class);
        String title = entry.getTitle();            

        // We like blogs about Camel
        boolean good = title.toLowerCase().contains("camel");
        return good;
    }

}
Copy to Clipboard Toggle word wrap
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

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

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

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

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

会社概要

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

Theme

© 2025 Red Hat