fiware - 订阅 CB 有效但不可见

标签 fiware fiware-orion fiware-cygnus

我有一个在上下文代理上表示的实体,具有多个属性(例如温度、湿度等...)。我有一个 MySql 数据库,它按保存该实体的值。因此,为了保留该信息,我必须从 cygnus 订阅。这里的问题是信息被保留,但是当我运行命令 (curl http://localhost:1026/v2/subscription) 我得到输出:[] 就像正在进行任何订阅一样。如果我执行命令 echo 'db.csubs.count()' | mongo orion --quiet 它甚至显示输出 0。

运行操作系统:Centos 6 我的 Orion Context Broker 版本:0.26.0

Orion 作为服务运行:

/usr/bin/contextBroker -port 1026 -logDir/var/log/contextBroker -pidpath/var/run/contextBroker/contextBroker.pid -dbhost localhost -db orion -multiservice

所以从第一步开始。假设我没有对数据库进行任何订阅。我运行命令:

/usr/cygnus/bin/cygnus-flume-ng agent --conf /usr/cygnus/conf/ -f /usr/cygnus/conf/agent_a1.conf -n cygnusagent -Dflume.root.logger=INFO,console

确保 Flume 代理正在运行。

python2.7 SetSubscription.py bus temperature http://188.???.??.???:5050/notify

Python 脚本是 github 存储库中的 fiware-figway 文件夹中提供的脚本。

import requests, json, re
from collections import Counter
import ConfigParser
import io
import sys

CONFIG_FILE = "../config.ini"

NUM_ARG=len(sys.argv)
COMMAND=sys.argv[0]

if NUM_ARG==4:
   ENTITY_ID=sys.argv[1]
   ENTITY_ATTR=sys.argv[2]
   SERVER_URL=sys.argv[3]
else:
   print 'Usage: '+COMMAND+' [ENTITY ID] [ATTRIBUTE] [SERVER URL]'
   print '  ENTITY ID = Entity you want to watch for changes/updates.'
   print '  ATTRIBUTE = Attribute whose change will trigger notifications. In this example script only this attribute will be notified.'
   print '  SERVER URL = (Local) Server listening for notifications.Example: http://myserver.domain.com:10000'
   print '    It has to be a reachable address:port for the ContextBroker. If you are behind a NAT/Firewall contact your network admin.'
   print
   sys.exit(2)


# Load the configuration file
with open(CONFIG_FILE,'r+') as f:
    sample_config = f.read()
config = ConfigParser.RawConfigParser(allow_no_value=True)
config.readfp(io.BytesIO(sample_config))

CB_HOST=config.get('contextbroker', 'host')
CB_PORT=config.get('contextbroker', 'port')
CB_FIWARE_SERVICE=config.get('contextbroker', 'fiware_service')
CB_AAA=config.get('contextbroker', 'OAuth')
if CB_AAA == "yes":
   TOKEN=config.get('user', 'token')
   TOKEN_SHOW=TOKEN[1:5]+"**********************************************************************"+TOKEN[-5:]
else:
   TOKEN="NULL"
   TOKEN_SHOW="NULL"

NODE_ID=config.get('local', 'host_id')
f.close()

CB_URL = "http://"+CB_HOST+":"+CB_PORT
MIN_INTERVAL = "PT5S"
DURATION = "P1M"
ENTITY_TYPE = ""
ENTITY_ATTR_WATCH = ENTITY_ATTR
ENTITY_ATTR_NOTIFY = ENTITY_ATTR

PAYLOAD = '{ \
    "entities": [ \
        { \
            "type": "'+ENTITY_TYPE+'", \
            "isPattern": "false", \
            "id": "'+ENTITY_ID+'" \
        } \
    ], \
    "attributes": [ \
        "'+ENTITY_ATTR_NOTIFY+'" \
    ], \
    "reference": "'+SERVER_URL+'", \
    "duration": "'+DURATION+'", \
    "notifyConditions": [ \
        { \
            "type": "ONCHANGE", \
            "condValues": [ \
                "'+ENTITY_ATTR_WATCH+'" \
            ] \
        } \
    ], \
    "throttling": "'+MIN_INTERVAL+'" \
}'

HEADERS = {'content-type': 'application/json', 'accept': 'application/json' , 'Fiware-Service': CB_FIWARE_SERVICE ,'X-Auth-Token' : TOKEN}
#HEADERS = {'content-type': 'application/json', 'Fiware-Service': CB_FIWARE_SERVICE ,'X-Auth-Token' : TOKEN}
HEADERS_SHOW = {'content-type': 'application/json', 'accept': 'application/json' , 'Fiware-Service': CB_FIWARE_SERVICE , 'X-Auth-Token' : TOKEN_SHOW}
URL = CB_URL + '/v1/subscribeContext'

print "* Asking to "+URL
print "* Headers: "+str(HEADERS_SHOW)
print "* Sending PAYLOAD: "
print json.dumps(json.loads(PAYLOAD), indent=4)
print
print "..."
r = requests.post(URL, data=PAYLOAD, headers=HEADERS)
print
print "* Status Code: "+str(r.status_code)
print
print r.text

现在,每次我更改值时,该值都会更改并保存在数据库中。

如果您需要更多信息,请随时询问!

编辑:

有效负载“询问”、“ header :”和“发送有效负载”:

* Asking to http://188.???.??.???:1026/v1/subscribeContext
* Headers: {'Fiware-Service': 'fiwarefinal', 'content-type': 'application/json', 'accept': 'application/json', 'X-Auth-Token': 'NULL'}
* Sending PAYLOAD:
{
    "reference": "http://localhost:5050/notify",
    "throttling": "PT5S",
    "entities": [
        {
            "type": "",
            "id": "bus1",
            "isPattern": "false"
        }
    ],
    "attributes": [
        "temperature"
    ],
    "duration": "P1M",
    "notifyConditions": [
        {
            "condValues": [
                "temperature"
            ],
            "type": "ONCHANGE"
        }
    ]
}

...

* Status Code: 200

{
  "subscribeResponse" : {
    "subscriptionId" : "56781c2d071f621a6546e740",
    "duration" : "P1M",
    "throttling" : "PT5S"
  }
}

最佳答案

请注意,您正在多服务模式下运行 Orion。因此,实体/属性/订阅被 MongoDB 层的不同数据库中的租户/服务完全隔离。特别要注意的是,订阅上下文请求使用 Fiware-Service: fiwarefinal因此订阅是在“fiwarefinal”服务中创建的(与 orion-fiwarefinal DB 关联)。

因此curl http://localhost:1026/v2/subscription不会显示任何订阅,因为订阅查询在默认租户(与 orion 数据库关联)​​中解析。 echo 'db.csubs.count()' | mongo orion --quiet 相同。为了获取“fiwarefinal”服务的订阅列表(或在数据库中计数),您应该使用:

  • curl --header 'Fiware-Service: fiwarefinal' http://localhost:1026/v2/subscription
  • echo 'db.csubs.count()' | mongo orion-fiwarefinal --quiet

请注意,您还需要使用 Fiware-Service: fiwarefinal如果您想删除“fiwarefinal”租户/服务中的订阅,请在取消订阅上下文操作中进行。

请查找有关 multiservice mode 的更多信息和 how it relates with DB level .

关于fiware - 订阅 CB 有效但不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399054/

相关文章:

javascript - SpagoBI:使用查询数据集结果的脚本数据集

fiware - 如何从 Orion 获取所有者插入的所有订阅

fiware - 模糊搜索并尝试在 Orion 中创建实体失败

mongodb - FIWARE Cygnus 在空间使用方面有任何问题吗?

subscription - FIWARE QuantumLeap 健全性检查失败 : QuantumLeap can't get changed data from Orion

hadoop - 固件 Cosmos Hive 授权问题

fiware-orion - 如何使用 Cygnus 将 Orion 与公共(public) cosmos.lab.fi-ware.org 实例连接起来

java - 找不到 Fiware Cygnus 处理程序

fiware-orion - 使用 Docker-compose 安装的 Cygnus-ngsi 不会将数据保存在 MongoDB 中

fiware-orion - Fiware - Cygnus 到 Cosmos,我无法上传数据到 HDFS