328.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 つの落とし穴は、ファイルが再度開かれ、scanStreamDelay の反復ごとにスキャンされることです。NIO2 が利用可能になるまで、ファイルが削除/再作成されたことを確実に検出することはできません。