257.6. 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
257.6.1. direct 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:" エンドポイントを使用してルートを定義する必要はありません(hood では使用されません)。
この場合、Camel 変換は以下を行います。
from("direct:process")
.marshal() // ... other details