搜索

267.6. 例子

download PDF

267.6.1. 发布事件

生成时的默认操作.以下片段将 PojoBean 生成的事件发布到频道 iot。

from("timer:mytimer")
    // generate some data as POJO.
    .bean(PojoBean.class)
    .to("pubnub:iot?publishKey=mypublishKey");

267.6.2. 触发事件 aka BLOCKS Event Handlers

有关可调用的所有无服务器功能类型,请参阅 https://www.pubnub.com/blocks-catalog/。地理位置查找示例

from("timer:geotimer")
    .process(exchange -> exchange.getIn().setBody(new Foo("bar", "TEXT")))
    .to("pubnub:eon-maps-geolocation-input?operation=fire&publishKey=mypubkey&subscribeKey=mysubkey");

from("pubnub:eon-map-geolocation-output?subscribeKey=mysubkey)
    // geolocation output will be logged here
    .log("${body}");

267.6.3. 订阅事件

以下片段侦听 iot 频道上的事件。如果您可以使用Presens 添加选项,您也会接收频道 Join,Leaave asf 事件。

from("pubnub:iot?subscribeKey=mySubscribeKey")
    .log("${body}")
    .to("mock:result");

267.6.4. 执行操作

在这里:获取有关频道当前状态的信息,包括当前订阅了频道的唯一 user-ids 列表以及频道总数

from("direct:control")
    .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=herenow")
    .to("mock:result");

其中现在:获取有关订阅 uuid 的当前频道列表的信息

from("direct:control")
    .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=wherenow&uuid=spyonme")
    .to("mock:result");

setstate : used 用来设置特定于订阅者 uuid 的键/值对。

from("direct:control")
    .bean(StateGenerator.class)
    .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=setstate&uuid=myuuid");

gethistory :显示频道的历史消息。

from("direct:control")
    .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=gethistory");

测试目录中有几个示例显示了 PubNub 功能。它们需要一个 PubNub 帐户,您可以在其中获取发布和订阅密钥。

示例 PubNubSensorExample 已经包含 PubNub 提供的订阅密钥,因此可以在没有帐户的情况下运行。这个示例演示了 PubNub 组件订阅一个无限的传感器数据流。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.