订阅CB正常但不可见 [英] Subscription to CB working but not visible
问题描述
我在Context Broker上表示了一个具有多个属性(例如温度,湿度等)的实体.我有一个MySql数据库,该数据库通过行保留了来自该实体的值.因此,为了保留该信息,我必须从天鹅座进行订阅.这里的问题是信息一直存在,但是当我运行命令(curl http://localhost:1026/v2/subscription)
时,我得到的输出是[]
,就像正在进行任何预订一样.如果我执行命令echo 'db.csubs.count()' | mongo orion --quiet
,它甚至显示输出0.
I have an entity represented on the Context Broker with severall attributes (such as temperature, humidity etc...). I have a MySql database that persists the values from that entity by row. So in order to persist that info i have to make a subscription from cygnus. The problem here is that the information is being presisted but when i run the command (curl http://localhost:1026/v2/subscription)
i get the output: []
as if any subscription was being made. If i do the command echo 'db.csubs.count()' | mongo orion --quiet
it even shows the output 0.
运行的操作系统:Centos 6 My Orion Context Broker版本:0.26.0
Running OS: Centos 6 My Orion Context Broker Version: 0.26.0
Orion作为服务运行:
Orion runs as a service:
/usr/bin/contextBroker -port 1026 -logDir /var/log/contextBroker -pidpath /var/run/contextBroker/contextBroker.pid -dbhost localhost -db orion -multiservice
因此从第一步开始.假设我没有对数据库进行任何订阅.我运行命令:
So from the first step. Let's assume i don't have any subscription made to the database. I run the command:
/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
确保水槽代理正在运行.
to ensure that a flume agent is running.
python2.7 SetSubscription.py bus temperature http://188.???.??.???:5050/notify
python脚本是github仓库中提供的fiware-figway文件夹中提供的脚本.
The python script is the one provided in the fiware-figway folder provided in the github repository.
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
现在,每次我更改值时,该值都会更改,并且该值将保留在数据库中.
Now everytime that i make a change in the values, the value is changed and it is presisted in the database.
如果您需要更多信息,请随时询问!
If you need any more information feel free to ask!
有效载荷向",标头:"和发送有效载荷":
The payload "Asking to ", "Headers: " and "Sending payload":
* 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关联)中创建的.
Note that you are running Orion in multiservice mode. Thus, entities/attributes/subscriptions are separated by tentant/services completely isolated in different databases at MongoDB layer. In particular, note that the subscribe context request is using Fiware-Service: fiwarefinal
so the subscription is created in the "fiwarefinal" service (associated to the orion-fiwarefinal
DB).
因此,curl http://localhost:1026/v2/subscription
将不会显示任何预订,因为在默认租户(与orion
数据库相关联)中解析了预订查询.对于echo 'db.csubs.count()' | mongo orion --quiet
也是一样.为了获取"fiwarefinal"服务的订阅列表(或以DB计),您应该使用:
Thus curl http://localhost:1026/v2/subscription
will not show any subscription, as the subscrition query is resolved in the default tenant (associated to the orion
database). The same for echo 'db.csubs.count()' | mongo orion --quiet
. In order to get the subscription list (or count in DB) for the "fiwarefinal" service you should use:
-
curl --header 'Fiware-Service: fiwarefinal' http://localhost:1026/v2/subscription
-
echo 'db.csubs.count()' | mongo orion-fiwarefinal --quiet
curl --header 'Fiware-Service: fiwarefinal' http://localhost:1026/v2/subscription
echo 'db.csubs.count()' | mongo orion-fiwarefinal --quiet
请注意,如果要删除"fiwarefinal"租户/服务中的订阅,则还需要在取消订阅上下文操作中使用Fiware-Service: fiwarefinal
.
Note that you also need to use Fiware-Service: fiwarefinal
in the unsubscribe context operation if you want to remove subscription in the "fiwarefinal" tenant/service.
请查找有关多服务模式的更多信息.并它与数据库级别的关系.
Please find, more information about multiservice mode and how it relates with DB level.
这篇关于订阅CB正常但不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!