搜索

331.5. Samples

download PDF

在以下示例中,我们将信息从 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 可用之前,我们无法可靠地检测文件何时被删除/创建。

如果要重新加载文件,如果文件滚动/重写,则您还应打开 fileWatcherretry 选项。

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

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.