Red Hat Training

A Red Hat training course is available for Red Hat Fuse

309.4. サンプル

以下の例では、direct:in エンドポイントから System.out ストリームにメッセージをルーティングします。

// Route messages to the standard output.
from("direct:in").to("stream:out");

// Send String payload to the standard output.
// Message will be followed by the newline.
template.sendBody("direct:in", "Hello Text World");

// Send byte[] payload to the standard output.
// No newline will be added after the message.
template.sendBody("direct:in", "Hello Bytes World".getBytes());

以下の例は、ヘッダータイプを使用して、使用するストリームを判別する方法を示しています。この例では、独自の出力ストリーム MyOutputStream を使用します。

以下の例は、ファイルストリームを継続的に読み取る方法を示しています(UNIX tail コマンドに似ています)。

from("stream:file?fileName=/server/logs/server.log&scanStream=true&scanStreamDelay=1000").to("bean:logService?method=parseLogLine");

scanStream(Camel 2.7 以前)または scanStream + retry が含まれる 1 つの gotcha は、scanStreamDelay の各反復でファイルを再度開き、スキャンします。NIO2 が利用可能になるまで、ファイルの削除/再作成時に確実に検出できません。