273.7. 请求转换至 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

273.7.1. 使用直接 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();

当使用 to () 方法而不是 toStream 时,不需要使用"reactive-streams:"端点(虽然它们在 hood 下使用了)来定义路由。

在这种情况下,Camel 转换可以只是:

from("direct:process")
.marshal() // ... other details
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部