273.7. Camel への変換のリクエスト

一部の Camel DSL で定義されたルートは、特定の変換を実行するためにリアクティブストリームフレームワーク内で使用できます (同じメカニズムを使用して、たとえば、http エンドポイントにデータを送信して続行することもできます)。

次のスニペットは、RxJava 機能コードがファイルをロードして Camel にマーシャリングするタスクを要求する方法を示しています。

CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);

// Process files starting from their names
Flowable.just(new File("file1.txt"), new File("file2.txt"))
    .flatMap(file -> camel.toStream("readAndMarshal", String.class))
    // Camel output will be converted to String
    // other steps
    .subscribe();

これを機能させるには、次のようなルートを Camel コンテキストで定義する必要があります。

from("reactive-streams:readAndMarshal")
.marshal() // ... other details

273.7.1. ダイレクト API を使用した Camel への変換のリクエスト

別のアプローチは、URI エンドポイントをリアクティブフローで直接使用することです。

CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);

// Process files starting from their names
Flowable.just(new File("file1.txt"), new File("file2.txt"))
    .flatMap(file -> camel.to("direct:process", String.class))
    // Camel output will be converted to String
    // other steps
    .subscribe();

toStream の代わりに to() メソッドを使用する場合、reactive-streams: エンドポイントを使用してルートを定義する必要はありません (内部では使用されますが)。

この場合、Camel 変換は次のようになります。

from("direct:process")
.marshal() // ... other details