【问题标题】:Fiware Context Provider hello world not workingFiware Context Provider hello world 不工作
【发布时间】:2021-05-10 11:58:53
【问题描述】:

我正在尝试将 Context Provider 注册为多个 KPI 的来源。

到目前为止,似乎注册可能有效,因为 GET http://{{orion}}/v2/registrations 返回的内容类似于我在创建时设置的内容:

{
    // each registering a new id is returned: "id": "60991a887032541f4539a71d",
    "description": "City Inhabitants",
    "dataProvided": {
        "entities": [
            {
                "id": "city.inhabitants"
                //,"type": "KeyPerformanceIndicator"
            }
        ]
    },
    "provider": {
        "http": {
            "url": "http://myhost/v2/inhabitants"
        }
        //, "legacyForwarding": false //perhaps there's a bug, cause although unset or set to false, broker still returns true.
    }
}

但是 GET http://{{orion}}/v2/entities/city.inhabitants 会导致:

{
    "error": "BadRequest",
    "description": "Service not found. Check your URL as probably it is wrong."
}

GET http://{{orion}}/v2/entities?type=KeyPerformanceIndicator 返回 [] 并且不会以任何方式调用 context-provider。

我正在从头开始编写 Node.js 应用程序,以便更好地了解 https://github.com/FIWARE/tutorials.Context-Providers 的情况,并使用教程容器作为实际的 Fiware Broker,因此所有 stores/shelf/products 都在工作但不是我的 KPI。

【问题讨论】:

  • "entities": [{"id": "city.inhabitants","type": "KeyPerformanceIndicator"}] 表示只有 idtype 的组合才会返回任何内容。尝试删除 id 或使用正则表达式
  • legacyForwarding 将以 NGSI-v1 格式返回 - 这不再是必需的
  • @JasonFox 关于 legacyForwarding:根据github.com/telefonicaid/fiware-orion/issues/…,如果未设置应为 false,但代理仍返回 legacyForwarding=true。也许它是一个错误?
  • 可能,我的意思是您的示例中不需要它,现在可以忽略。
  • @JasonFox 不是 id+type 的用法需要同时使用两者,如 fiware-orion.readthedocs.io/en/master/user/context_providers/… 所述,这是一种好的做法? > 在转发时,NGSIv2 更新/查询中的任何类型的实体都匹配没有实体类型的注册。但是,相反的方法不起作用,因此如果您注册了类型,那么您必须在 NGSIv2 更新/查询中使用 ?type 以获得匹配。否则你可能会遇到问题,就像 StackOverflow 上的这篇文章中描述的那样。

标签: fiware fiware-orion


【解决方案1】:

使用教程应用程序,其中微服务正在侦听 http://context-provider:3000/random/weatherConditions POST 端点。

以下注册:

curl -L -X POST 'http://localhost:1026/v2/registrations' \
-H 'Content-Type: application/json' \
--data-raw '{
   "description": "Get Weather data for KPI 1",
   "dataProvided": {
     "entities": [
       {
         "id" : "urn:ngsi-ld:KPI:010",
         "type": "KeyPerformanceIndicator"
       }
     ],
     "attrs": [
      "temperature", "relativeHumidity"
    ]
   },
   "provider": {
     "http": {
       "url": "http://context-provider:3000/random/weatherConditions"
     },
     "legacyForwarding": false
   },
   "status": "active"
}'

将为以下请求转发和检索数据:

curl -L -X GET 'http://localhost:1026/v2/entities/urn:ngsi-ld:KPI:010'

curl -L -X GET 'http://localhost:1026/v2/entities/?type=KeyPerformanceIndicator'

返回:

{
    "id": "urn:ngsi-ld:KPI:010",
    "type": "KeyPerformanceIndicator",
    "temperature": {
        "type": "Number",
        "value": 11,
        "metadata": {}
    },
    "relativeHumidity": {
        "type": "Number",
        "value": 39,
        "metadata": {}
    }
}

上下文代理将请求转发到 http://context-provider:3000/random/weatherConditions POST 端点,并带有以下负载:

{
 "entities": [
  {
   "id": "urn:ngsi-ld:KPI:010",
   "type": "KeyPerformanceIndicator"
  }
 ],
 "attrs": [
  "temperature",
  "relativeHumidity"
 ]
}

【讨论】:

  • 这都是真的......到目前为止,我看到的唯一区别是我在尝试重定向到 myhost/v2/inhabitants 时遇到问题...
  • 由于尝试内部(docker)端点正在工作,问题应该与请求有关,所以 docker logs -f containerid 转储了一个澄清“无法发布 /v2/inhabitants /操作/查询”。事实上,我的节点应用程序正在监听 GET 请求而不是 POST :( 谢谢@JasonFox。顺便说一句:为 FIWARE 创建一个 Discord 频道不是很好吗???(咳嗽,咳嗽,请,咳嗽,咳嗽)
猜你喜欢
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 2013-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多