【问题标题】:Notify python orion/quantumleap subscription changes通知 python orion/quantumleap 订阅更改
【发布时间】:2023-01-29 23:57:32
【问题描述】:

当 Quantumleap o Orion 订阅因更改的值而触发时,有什么方法可以在 python 中得到通知吗?

我正在尝试使用此 python 代码(感谢nickjj)监听 HTTP 请求,它正在监听localhost:8008(确实有效,如果我访问监听地址,我可以看到打印的标题),但我可以从 Orion 那里得到任何通知。

from http.server import HTTPServer, BaseHTTPRequestHandler
from sys import argv

BIND_HOST = 'localhost'
PORT = 8008

class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.write_response(b'')

    def do_POST(self):
        content_length = int(self.headers.get('content-length', 0))
        body = self.rfile.read(content_length)

        self.write_response(body)

    def write_response(self, content):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(content)

        print(self.headers)
        print(content.decode('utf-8'))


if len(argv) > 1:
    arg = argv[1].split(':')
    BIND_HOST = arg[0]
    PORT = int(arg[1])

print(f'Listening on http://{BIND_HOST}:{PORT}\n')

httpd = HTTPServer((BIND_HOST, PORT), SimpleHTTPRequestHandler)
httpd.serve_forever()

我已经在 Orion 中配置了相关订阅

curl -iX POST \
    'http://localhost:1026/v2/subscriptions/' \
    -H 'Content-Type: application/json' \
    -H 'fiware-service: opcua_car' \
    -H 'fiware-servicepath: /demo' \
    -d '{
  "description": "Subscriptions for Python",
  "subject": {
    "entities": [
      {
        "idPattern": ".*",
        "type": "PLC"
      }
    ],
    "condition": {
      "attrs": [
        "processStatus"
      ]
    }
  },
  "notification": {
    "http": {
      "url": "http://localhost:8008"
    },
    "attrs": [
      "processStatus"
    ],
    "metadata": [
      "dateCreated",
      "dateModified"
    ]
  },
  "throttling": 1
}'

【问题讨论】:

    标签: python fiware fiware-orion


    【解决方案1】:

    我认为接收来自 Orion 的 HTTP 通知的最简单方法是设置一个 http 服务器来监听 Python 代码中的那些通知(http 请求)。例如,使用Flask

    最好。

    【讨论】:

    • 是的,无论你实现 n Python、C、node、js 还是任何其他语言,通知都会作为 HTTP 请求发送(除非你更喜欢 MQTT,这也是一个选项)。您的实施只需要准备好接收信息。
    • 您是否有任何与 Orion 相关的代码可以作为参考?
    • 我已经添加了我现在结束的代码,如果您对为什么不工作有任何提示,我们将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多