You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从PERSEO CEP向Orion CB创建订阅并配置指定指令与永久MAX_AGE

实现PERSEO CEP与Orion Context Broker的订阅及规则触发

我来帮你一步步完成从PERSEO CEP到Orion Context Broker的订阅配置,确保属性变化时能触发PERSEO规则,同时正确设置你提到的三个关键参数。

一、关键参数说明与配置

先明确你提到的三个参数的作用和正确配置方式:

1. PERSEO_NOTICES_PATH 和 PERSEO_RULES_PATH

这两个是PERSEO Frontend的环境变量,用来定义规则和通知的API路径。你已经在perseo-front容器里设置了PERSEO_NOTICES_PATH='/notices'和PERSEO_RULES_PATH='/rules',这个配置完全正确,后续调用API时就用这些路径(比如http://perseo-fe:9090/rules来创建规则)。

2. MAX_AGE 设置为永久/多年

Orion的maxAge参数控制订阅的有效期,单位是秒。如果要设置为永久,Orion支持用0表示无过期(永久有效);如果要设置多年,比如5年,计算对应的秒数即可:5年=5×365×24×3600=157680000秒。

注意:你的perseo-core容器里原来设置的MAX_AGE=9999只有约2.7小时,不符合需求,需要修改。如果要永久就设为MAX_AGE=0;如果要多年,就填对应的秒数(比如5年填157680000)。

二、修正后的容器配置

我帮你修正了perseo-core的MAX_AGE配置,同时整理了容器YAML,解决了perseo-front镜像重复的问题:

perseo-core:
  image: fiware/perseo-core
  hostname: perseo-core
  container_name: fiware-perseo-core
  depends_on:
    - mongo-db
    - orion
  networks:
    - smartcity
  ports:
    - "8080:8080"
  environment:
    - PERSEO_FE_URL=http://perseo-fe:9090
    - MAX_AGE=0  # 0表示永久有效,若要5年则改为157680000

perseo-front:
  image: fiware/perseo
  hostname: perseo-fe
  container_name: fiware-perseo-fe
  networks:
    - smartcity
  ports:
    - "9090:9090"
  depends_on:
    - perseo-core
  environment:
    - PERSEO_ENDPOINT_HOST=perseo-core
    - PERSEO_ENDPOINT_PORT=8080
    - PERSEO_MONGO_HOST=mongo-db
    - PERSEO_MONGO_URL=http://mongo-db:27017
    - PERSEO_MONGO_ENDPOINT=mongo-db:27017
    - PERSEO_ORION_URL=http://orion:1026/
    - PERSEO_LOG_LEVEL=debug
    - PERSEO_CORE_URL=http://perseo-core:8080
    - PERSEO_SMTP_SECURE=true
    - PERSEO_MONGO_USER="root"
    - PERSEO_MONGO_PASSWORD="example"
    - PERSEO_SMTP_HOST=x
    - PERSEO_SMTP_PORT=25
    - PERSEO_SMTP_AUTH_USER=x
    - PERSEO_SMTP_AUTH_PASS=x
    - PERSEO_NOTICES_PATH='/notices'
    - PERSEO_RULES_PATH='/rules'

注意:perseo-front原来的image字段重复了,我保留了官方的fiware/perseo镜像,避免启动冲突。

三、创建Orion订阅,让PERSEO接收属性变化通知

接下来需要向Orion Context Broker创建订阅,指定当某个实体的属性变化时,通知发送到PERSEO的/notices路径。

示例订阅请求(用curl)

假设你要监控Room类型实体的temperature属性,当温度变化时通知PERSEO:

curl -X POST http://orion:1026/v2/subscriptions \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Notify PERSEO when Room temperature changes",
    "subject": {
      "entities": [
        {
          "idPattern": ".*",
          "type": "Room"
        }
      ],
      "condition": {
        "attrs": [
          "temperature"
        ]
      }
    },
    "notification": {
      "http": {
        "url": "http://perseo-fe:9090/notices"  # 对应PERSEO_NOTICES_PATH配置的路径
      },
      "attrs": [
        "temperature"
      ]
    },
    "expires": "2030-01-01T00:00:00Z",  # 可选,和MAX_AGE=0配合,设置为远期时间更保险
    "throttling": 5
  }'

说明:

  • expires字段如果设置为很远的时间(比如2030年),能进一步确保订阅长期有效,和MAX_AGE=0搭配使用更稳妥。
  • throttling是节流时间,避免短时间内重复触发通知,单位是秒。

四、在PERSEO中创建规则,触发动作

订阅成功后,需要在PERSEO中创建规则,当收到Orion的通知时执行指定动作(比如发送邮件、调用第三方API等)。

示例规则创建请求(用curl)

curl -X POST http://perseo-fe:9090/rules \
  -H "Content-Type: application/json" \
  -d '{
    "name": "HighTemperatureAlert",
    "text": "select *, temperature as temp from pattern [every ev=iotEvent(cast(temp, float) > 30)]",
    "action": {
      "type": "email",
      "parameters": {
        "to": "alert@example.com",
        "subject": "High Temperature Alert",
        "body": "Temperature is {{temp}} degrees in room {{id}}"
      }
    }
  }'

这个规则会在温度超过30度时发送邮件通知,你可以根据需求修改action的类型和参数(比如改为HTTP请求、短信通知等)。

五、验证流程

  1. 启动所有容器:docker-compose up -d
  2. 发送实体属性更新请求到Orion,触发订阅:
    curl -X PATCH http://orion:1026/v2/entities/Room1/attrs/temperature \
      -H "Content-Type: application/json" \
      -d '{
        "value": 35,
        "type": "Number"
      }'
    
  3. 查看PERSEO日志确认规则触发:docker logs fiware-perseo-fe,同时检查是否收到对应的通知(比如邮件)。

内容的提问来源于stack exchange,提问作者Antonio Moreno Borras

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:26:03