0

使用 CEP 我正在尝试制作 Proton 和 Orion 之间通信的基本示例。我只是想让 Proton 接收来自 Orion 的温度通知,如果温度值高于或等于 20,则发回一个更改一个布尔属性的有效负载。

这是我正在使用的定义。

{
    "epn":
    {
        "events":
        [
            {
                "name": "TemperatureContextUpdate",
                "attributes":
                [
                    {
                        "dimension": 0,
                        "description": "The certainty that this event happen (value between 0 to 1)",
                        "name": "Certainty",
                        "defaultValue": "1",
                        "type": "Double"
                    },
                    {
                        "dimension": 0,
                        "description": "No value means it equals the event detection time, other option is to use one of the defined distribution functions with parameters",
                        "name": "OccurrenceTime",
                        "type": "Date"
                    },
                    {
                        "dimension": 0,
                        "name": "ExpirationTime",
                        "type": "Date"
                    },
                    {
                        "dimension": 0,
                        "description": "The cost of this event occurrence. Negative if this is an opportunity",
                        "name": "Cost",
                        "type": "Double"
                    },
                    {
                        "dimension": 0,
                        "description": "Used in case the this event occur within an interval",
                        "name": "Duration",
                        "defaultValue": "0",
                        "type": "Double"
                    },
                    {
                        "dimension": "0",
                        "name": "entityId",
                        "type": "String"
                    },
                    {
                        "dimension": "0",
                        "name": "entityType",
                        "type": "String"
                    },
                    {
                        "dimension": "0",
                        "name": "temperature",
                        "type": "Integer"
                    },
                    {
                        "dimension": "0",
                        "name": "chaud",
                        "type": "Boolean"
                    }
                ],
                "createdDate": "Wed Feb 22 2017"
            },
            {
                "name": "Out_TemperatureContextUpdate",
                "attributes":
                [
                    {
                        "dimension": 0,
                        "description": "The certainty that this event happen (value between 0 to 1)",
                        "name": "Certainty",
                        "defaultValue": "1",
                        "type": "Double"
                    },
                    {
                        "dimension": 0,
                        "description": "No value means it equals the event detection time, other option is to use one of the defined distribution functions with parameters",
                        "name": "OccurrenceTime",
                        "type": "Date"
                    },
                    {
                        "dimension": 0,
                        "name": "ExpirationTime",
                        "type": "Date"
                    },
                    {
                        "dimension": 0,
                        "description": "The cost of this event occurrence. Negative if this is an opportunity",
                        "name": "Cost",
                        "type": "Double"
                    },
                    {
                        "dimension": 0,
                        "description": "Used in case the this event occur within an interval",
                        "name": "Duration",
                        "defaultValue": "0",
                        "type": "Double"
                    },
                    {
                        "dimension": "0",
                        "name": "entityId",
                        "type": "String"
                    },
                    {
                        "dimension": "0",
                        "name": "entityType",
                        "type": "String"
                    },
                    {
                        "dimension": "0",
                        "name": "temperature",
                        "type": "Integer"
                    },
                    {
                        "dimension": "0",
                        "name": "chaud",
                        "type": "Boolean"
                    }
                ],
                "createdDate": "Wed Feb 22 2017"
            }
        ],
        "name": "TemperatureDemo",
        "consumers":
        [
            {
                "events":
                [
                    {
                        "name": "Out_TemperatureContextUpdate"
                    }
                ],
                "name": "Consumer_Rest",
                "properties":
                [
                    {
                        "name": "URL",
                        "value": "http://172.17.0.3:1026/v2/entities"
                    },
                    {
                        "name": "contentType",
                        "value": "application/json"
                    },
                    {
                        "name": "formatter",
                        "value": "json_ngsi"
                    },
                    {
                        "name": "delimiter",
                        "value": ";"
                    },
                    {
                        "name": "tagDataSeparator",
                        "value": "="
                    },
                    {
                        "name": "dateFormat",
                        "value": "dd/MM/yyyy-HH:mm:ss"
                    }
                ],
                "type": "Rest",
                "createdDate": "Wed Feb 22 2017"
            },
            {
                "events":
                [
                    {
                        "name": "TemperatureContextUpdate"
                    }
                ],
                "name": "Consumer_File",
                "properties":
                [
                    {
                        "name": "filename",
                        "value": "/home/work/Documents/test.txt"
                    },
                    {
                        "name": "formatter",
                        "value": "json"
                    },
                    {
                        "name": "delimiter",
                        "value": ";"
                    },
                    {
                        "name": "tagDataSeparator",
                        "value": "="
                    }
                ],
                "type": "File",
                "createdDate": "Wed Feb 22 2017"
            }
        ],
        "epas":
        [
            {
                "inputEvents":
                [
                    {
                        "instanceSelectionPolicy": "First",
                        "alias": "TemperatureContextUpdate",
                        "filterExpression": "TemperatureContextUpdate.temperature>=20",
                        "name": "TemperatureContextUpdate",
                        "consumptionPolicy": "Consume"
                    }
                ],
                "derivedEvents":
                [
                    {
                        "name": "Out_TemperatureContextUpdate",
                        "reportParticipants": false,
                        "expressions":
                        {
                            "Cost": "TemperatureContextUpdate.Cost",
                            "Certainty": "TemperatureContextUpdate.Certainty",
                            "OccurrenceTime": "TemperatureContextUpdate.OccurrenceTime",
                            "Duration": "TemperatureContextUpdate.Duration",
                            "entityId": "TemperatureContextUpdate.entityId",
                            "ExpirationTime": "TemperatureContextUpdate.ExpirationTime",
                            "chaud": "true",
                            "entityType": "TemperatureContextUpdate.entityType",
                            "temperature": "TemperatureContextUpdate.temperature"
                        }
                    }
                ],
                "evaluationPolicy": "Immediate",
                "name": "EPA_Change",
                "internalSegmentation":
                [
                ],
                "context": "always",
                "epaType": "Basic",
                "cardinalityPolicy": "Single",
                "localPlacement": true,
                "createdDate": "Wed Feb 22 2017",
                "computedVariables":
                [
                ]
            }
        ],
        "optimization":
        {
        },
        "contexts":
        {
            "temporal":
            [
                {
                    "terminators":
                    [
                    ],
                    "neverEnding": true,
                    "atStartup": true,
                    "name": "always",
                    "type": "TemporalInterval",
                    "createdDate": "Wed Feb 22 2017",
                    "initiators":
                    [
                    ]
                }
            ],
            "segmentation":
            [
            ],
            "composite":
            [
            ]
        },
        "producers":
        [
        ]
    }
}

我尝试在收到第一次更新时创建一个文件,但这个文件总是空的,顺便说一句,它是在我的目录中正确创建的,并且每次我更改定义时都会更改。其余的有效负载永远不会发送,就像条件永远不会触发一样。

我发送的有效载荷:

{
 "subscriptionId": "51c04a21d714fb3b37d7d5a7",
 "data": 
[ {
"id": "temp1",
 "type": "Temperature",
 "temperature": {
    "type":"integer",
    "value": 28,
    "metadata":{}
},
"chaud": {
    "type":"boolean",
    "value": false,
    "metadata":{}
},
    "Certainty": {
        "value": "1",
        "type": "Float"
    },
    "Cost": {
        "value": "0",
        "type": "Float"
    },
    "Name": {
        "value": "",
        "type": "String"
    },
    "EventSource": {
        "value": "",
        "type": "String"
    },
    "Duration": {
        "value": "0",
        "type": "Float"
    }
}
]
}

日志 catalina.out :

INFOS:启动事件消息正文阅读器 févr。2017 年 2 月 23 日上午 11:23:35 com.ibm.hrl.proton.webapp.providers.EventJSONNgsiMessageReader parseVTwoFormat INFOS:事件:TemperatureContextUpdate févr。2017 年 2 月 23 日上午 11:23:35 com.ibm.hrl.proton.webapp.providers.EventJSONNgsiMessageReader readFrom INFOS:完成的事件消息正文阅读器 févr。2017 年 2 月 23 日上午 11:23:35 com.ibm.hrl.proton.webapp.providers.EventJSONNgsiMessageReader 从 INFOS 读取:EventJSONNgsiMessageReader:读取事件 TemperatureContextUpdate;实体 ID=temp1;EventId=ba868559-7589-4720-ab75-658b920a3f14;乔德=假;实体类型=温度;计时=空;温度=28;检测时间=1487845415319;名称=; 确定性=1;成本=0;事件源=; 发生时间=空;持续时间=0;注释=; 过期时间=空;从经纪人... févr。2017 年 2 月 23 日上午 11:23:35 com.ibm.hrl.proton.webapp.resources。EventResource submitNewEvent INFOS:开始 submitNewEvent févr。2017 年 2 月 23 日上午 11:23:35 com.ibm.hrl.proton.webapp.resources.EventResource submitNewEvent INFOS:发送到质子运行时的事件...

所以知道我的问题在哪里吗?

谢谢。

4

1 回答 1

0

您的错误是您发送的事件名称为空。我很抱歉在输入中重复了相同的信息,但是这来自 Proton 和 Orion 之间的集成,每个都需要不同形式的信息,并且差异没有被顺利修补。

您应该发送的输入应包含输入事件名称,如下所示:

{
 "subscriptionId": "51c04a21d714fb3b37d7d5a7",
 "data": 
[ {
"id": "temp1",
 "type": "Temperature",
 "temperature": {
    "type":"integer",
    "value": "28",
    "metadata":{}
},
"chaud": {
    "type":"boolean",
    "value": false,
    "metadata":{}
},
    "Certainty": {
        "value": "1",
        "type": "Float"
    },
    "Cost": {
        "value": "0",
        "type": "Float"
    },
    "Name": {
        "value": "TemperatureContextUpdate",
        "type": "String"
    },
    "EventSource": {
        "value": "",
        "type": "String"
    },
    "Duration": {
        "value": "0",
        "type": "Float"
    }
}
]
}

请注意,名称属性现在具有值“TemperatureContextUpdate”

于 2017-02-28T15:53:32.227 回答