1
是否可以从浏览器创建websockets订阅?我们使用分支功能/ 1181_websockets分支,git版本5ca6770aa401b52a31293fdcef4a9743fb1de2c4。通过Orion中的websockets订阅
我们做了一个PoC试图通过websockets订阅浏览器。我们尝试将浏览器中运行的一些JS代码连接到订阅网址。连接已建立,但通过套接字从客户端发送数据时,orion崩溃。这个用例是否支持?你有一个工作的例子吗? JS代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="send" type="button" name="button">send</button>
<script type="text/javascript">
var payload = `{"description": "One subscription to rule them all",
"subject": {
"entities": [{
"idPattern": ".*",
"type": "Room"
}],
"condition": {
"attrs": ["temperature"],
"expression": {
"q": "temperature>40"
}
}
},
"expires": "2016-04-05T14:00:00.00Z",
"throttling": 5
}`;
var ws = new WebSocket('ws://orion-url:9010/v2/subscriptions', 'ngsiv2-json');
var button = document.getElementById('send');
button.addEventListener('click', function(event) {
ws.send(payload)
});
</script>
</body>
</html>
作为替代,我们尝试使用REST API创建订阅,要求Orion通过websockets通知我们。我们发布了以下JSON:
{
"description": "One subscription to rule them all",
"subject": {
"entities": [
{
"idPattern": ".*",
"type": "Room"
}
],
"condition": {
"attributes": [
"temperature"
],
"expression": {
"q": "temperature>40"
}
}
},
"notification": {
"callback": "ws://my-websocket-listener:8081"
},
"expires": "2016-04-05T14:00:00.00Z",
"throttling": 5
}
订阅进程失败和猎户座返回422个状态码与消息:
{
"error": "BadRequest",
"description": "Invalid URL"
}
难道我们做出的订阅请求的任何错误?这个用例是否支持?
谢谢!
功能/ 1181_websockets是一个实验分支,在某种意义上说,是一个“动态图片”。为了知道你有哪个确切的CB版本(来自'contextBroker --version'输出),你可以编辑你的问题帖子来包含这些信息吗?重要的部分是githash。谢谢! – fgalan
感谢您的回复。我用这些信息编辑了我的问题。 –