この例は、Cepheus-CEP 内でのメタデータ・マッピングの使用を示しています。

これは完全にルームとフロアの例に基づいています。

これは、temperature 属性の unit メタデータを伝播する方法を示しています。

セットアップ

センサによって生成されたコンテキスト・エンティティには、unit メタデータが含まれています :

 {
     "id": "Room31", // Room 1 on floor 3 (could be anything else)
     "type":"Room",  // all sensors must use the same "Room" type
     "attributes": [
        {
            "name":"temperature",
            "type":"double",
            "value":"21",
            "metadatas": [
                { "name":"unit", "type":"string", "value":"celsius" }
            ]
        },
        { "name":"floor", "type":"string", "value":"3" } // the room is on the third foor
     ]
 }

CEPは次のように値を出力することを期待しています :

{
    "id": "Floor1", // uniquely identifies a floor (coud be anything else)
    "type":"Floor", // all floor must use the same "Floor" type
    "attributes": [
        {
            "name":"temperature",
            "type":"double",
            "value":"23.3",
            "metadatas": [
                { "name":"unit", "type":"string", "value":"celsius" }
            ]
        }
    ]
}

CEPの設定

Cepheus-CEP の設定フォーマットに変換されているので、入力として室温を受け入れるための以下の "in "セクションがあります :

"in": [
    {
        "id":"Room.*",     # Pattern is used to subscribe to provider to all Room1, Room2, ..., RoomN
        "type":"Room",     # The type to subscribe
        "isPattern":true,  # Pattern match the id
        "providers": [ "http://localhost:8081" ],  # The URL of the source of the input
        "attributes":[
            {
                "name":"temperature",
                "type":"double",
                "metadata": [
                   { "name":"unit", "type":"string" }
                ]
            },
            { "name":"floor", "type":"string" }
        ]
    }
]

"out" セクションは、フロアの NGSI コンテキスト・エンティティにも似ています :

"out":[
    {
        "id":"Floor1",
        "type":"Floor",
        "attributes":[
            {
                "name":"temperature",
                "type":"double",
                "metadata": [
                    { "name":"unit", "type":"string" }
                ]
            }
        ]
    }
]

temperatureunit メタデータを送信するには、temperature_unit を"そのまま"送信するようにEPL ルールに指示する必要があります :

INSERT INTO Floor
SELECT floor as id, avg(temperature) as temperature, temperature_unit
FROM Room.win:time(10 minutes)
GROUP BY floor
OUTPUT LAST EVERY 1 min

EPL でのメタデータ命名の詳細については、CEP/マッピングセクション を参照してください。

config.json は、完全な設定のセットアップを持っています。

セットアップをテスト

run.sh ファイルを端末で実行し、Cepheus CEP のログをチェックすることで、CEP に送信された ルームの温度と CEP がイベントに反応することを確認できます。

最初の端末で、Cepheus-CEP を起動します :

cd cepheus-cep
mvn spring-boot:run

デフォルト設定では、マシン上の port :8080で起動する必要があります。

今度は別のターミナルで、run.sh スクリプトを起動します :

cd doc/examples/7_Metadata
sh run.sh

スクリプトは最初に config.json ファイルを Cepheus-CEP に送信し、温度の更新を送信します。

CEP を開始した端末に戻ります。"EventIn" が記録されていると温度が表示されます。

数秒後、"EventOut" ログに各フロアの平均温度をトリガする CEP が表示されます。