266.5. 例
266.5.1. イベントの公開
生成時のデフォルトの動作。次のスニペットは、PojoBean によって生成されたイベントをチャネル iot に発行します。
from("timer:mytimer") // generate some data as POJO. .bean(PojoBean.class) .to("pubnub:iot?publishKey=mypublishKey");
from("timer:mytimer")
// generate some data as POJO.
.bean(PojoBean.class)
.to("pubnub:iot?publishKey=mypublishKey");
266.5.2. BLOCKS イベントハンドラーとも呼ばれる Fire イベント
呼び出すことができるすべての種類のサーバーレス関数については、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}");
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}");
266.5.3. イベントのサブスクライブ
次のスニペットは、iot チャネルでイベントをリッスンします。オプション withPresens を追加できる場合は、チャネルの Join、Leave asf イベントも受信します。
from("pubnub:iot?subscribeKey=mySubscribeKey") .log("${body}") .to("mock:result");
from("pubnub:iot?subscribeKey=mySubscribeKey")
.log("${body}")
.to("mock:result");
266.5.4. 操作の実行
herenow : チャネルに現在サブスクライブしている一意のユーザー ID のリストや、チャネルの合計占有数など、チャネルの現在の状態に関する情報を取得します。
from("direct:control") .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=herenow") .to("mock:result");
from("direct:control")
.to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=herenow")
.to("mock:result");
wherenow : uuid がサブスクライブされているチャネルの現在のリストに関する情報を取得します
from("direct:control") .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=wherenow&uuid=spyonme") .to("mock:result");
from("direct:control")
.to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=wherenow&uuid=spyonme")
.to("mock:result");
setstate : サブスクライバー uuid に固有のキーと値のペアを設定するために使用されます。
from("direct:control") .bean(StateGenerator.class) .to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=setstate&uuid=myuuid");
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");
from("direct:control")
.to("pubnub:myChannel?publishKey=mypublishKey&subscribeKey=mySubscribeKey&operation=gethistory");
テストディレクトリーには、PubNub 機能のいくつかを示す例がいくつかあります。パブリッシュキーとサブスクライブキーを取得できる PubNub アカウントが必要です。
PubNubSensorExample の例には、PubNub によって提供されたサブスクライブキーがすでに含まれているため、これはアカウントなしで実行する準備ができています。この例は、センサーデータの無限ストリームにサブスクライブする PubNub コンポーネントを示しています。