331.5. Samples
在以下示例中,我们将消息从 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 (pre Camel 2.7)或 scanStream + retry 的 getcha,该文件将被重新打开并扫描每个 scanStreamDelay。在 NIO2 可用前,我们无法可靠地检测何时删除/创建文件。
如果要重新加载文件(如果为 rollover/rewritten),则您还应打开文件 Watcher 和 retry 选项。
from("stream:file?fileName=/server/logs/server.log&scanStream=true&scanStreamDelay=1000&retry=true&fileWatcher=true")
.to("bean:logService?method=parseLogLine");