272.6. 将数据发送到 Camel


当外部库需要将事件推送到 Camel 路由时,Reactive Streams 端点必须设置为使用者。

Copy to Clipboard Toggle word wrap
from("reactive-streams:elements")
.to("log:INFO");

元素 流的句柄可以从 CamelReactiveStreams 实用程序类获取。

Copy to Clipboard Toggle word wrap
CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);

Subscriber<String> elements = camel.streamSubscriber("elements", String.class);

订阅者可用于将事件推送到从 元素 流中消耗的 Camel 路由。

以下是如何将它与 RxJava 2 搭配使用的示例(尽管任何被动框架可用于发布事件)。

Copy to Clipboard Toggle word wrap
Flowable.interval(1, TimeUnit.SECONDS)
    .map(i -> "Item " + i)
    .subscribe(elements);

字符串项由示例中 RxJava 生成,它们被推送到以上定义的 Camel 路由中。

272.6.1. 使用直接 API 将数据发送到 Camel

在这种情况下,可以使用直接 API 从端点 URI 获取 Camel 订阅者。

Copy to Clipboard Toggle word wrap
CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);

// Send two strings to the "seda:queue" endpoint
Flowable.just("hello", "world")
    .subscribe(camel.subscriber("seda:queue", String.class));
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat, Inc.