Why this orion subscription don't works as I want?

邮差的信 提交于 2019-12-12 17:14:53

问题


I have the following subscription in orion 1.2.1:

curl  --include \
      --header 'Content-Type: application/json' \
      --request POST \
      --data-binary '{
                       "description": "subscription",
                       "subject": {
                         "entities": [
                           {
                             "idPattern": "event-.*",
                             "type": "Event"
                           }
                         ],
                         "condition": {
                           "attrs": [
                              "IdEvent",
                              "mFlag"
                           ],
                           "expression": {
                             "q": "mFlag>0"
                           }
                         }
                       },
                       "notification": {
                         "attrsFormat":"legacy",
                         "http": {
                             "url" : "http://localhost:5050/notify"
                         },
                         "attrs": [
                            "IdEvent"
                         ]
                       }
                     }' \
      'http://localhost:1026/v2/subscriptions'

When I send an entity update like this one:

curl --include \
     --request PATCH \
     --header "Content-Type: application/json" \
     --data-binary '{
                       "mFlag":{
                          "value":"5",
                          "type":"int"
                       }
                    }' \
                    'http://localhost:1026/v2/entities/event-2/attrs'

Orion is not notifiying and it is making me crazy don't know what is wrong. Any idea?

When I remove this part of the subscription:

"expression": {
   "q": "mFlag>0"
}

it works but I need it to notify when any attribute is changed and the condition is satisfied.


回答1:


Note that in NGSIv2 "5" is a string, not a number. Thus, in order to make the "q": "mFlag>0" filter works as expected, use the following update:

curl --include \
     --request PATCH \
     --header "Content-Type: application/json" \
     --data-binary '{
                       "mFlag":{
                          "value":5,
                          "type":"int"
                       }
                    }' \
                    'http://localhost:1026/v2/entities/event-2/attrs'


来源:https://stackoverflow.com/questions/38076588/why-this-orion-subscription-dont-works-as-i-want

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!