首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dockerize FIWARE无法通知服务

Dockerize FIWARE无法通知服务
EN

Stack Overflow用户
提问于 2021-09-02 01:36:30
回答 1查看 48关注 0票数 1

我刚开始使用FIWARE。我在PopOs发行版上使用docker-compose下载了最新版本的on the website (v2)。我使用Postman发出请求(创建实体和订阅),并使用Laravel应用程序侦听来自FIWARE订阅的通知。但由于某些原因,今天,当我启动docker服务并开始发送请求时: FIWARE通知突然停止工作。

当我访问订阅端点时,FIWARE返回:

代码语言:javascript
复制
        "notification": {
            "timesSent": 1,
            "lastNotification": "2021-09-02T01:19:39.000Z",
            "attrs": [],
            "onlyChangedAttrs": false,
            "attrsFormat": "keyValues",
            "http": {
                "url": "http://localhost:8000/api/notifications"
            },
            "lastFailure": "2021-09-02T01:19:39.000Z",
            "lastFailureReason": "Couldn't connect to server"
        }

FIWARE不能通信,但如果我使用Postman为该端点(http://localhost:8000/api/notifications)发出POST请求,它将返回200。

在FIWARE docker容器和本地机器之间有一些额外的配置吗?还是我做错了什么?

这是我的实体:

代码语言:javascript
复制
// http://{{orion}}/v2/subscription

{
    "id": "movie",
    "type": "movie",
    "name": {
        "type": "text",
        "value": "movie name"
    },
    "gender": {
        "type": "text",
        "value": "drama"
    }
}

这就是我订阅的方式:

代码语言:javascript
复制
// http://{{orion}}/v2/subscriptions

{
    "description": "Notify me about any movie of gender drama",
    "subject": {
        "entities": [{"idPattern": ".*","type": "movie"}],
        "condition": {
            "attrs": ["gender"],
            "expression": {
                "q": "gender==drama"
            }
        }
    },
    "notification": {
        "http": {
            "url": "http://127.0.0.1:8000/api/notifications"
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-02 09:56:52

如果你正在使用Docker,那么你需要考虑http://localhost:8000/api/notifications的实际含义。localhost指的是Orion容器本身所经历的localhost。一般情况下,Orion在1026上侦听,而在dockerized化的Orion中,8000上没有任何侦听,因此您的订阅失败。

如果您有另一个微服务运行在相同的docker网络和单独的容器中,则必须使用该容器的hostname (或alias或定义的IP)来描述通知hostname,而不是localhost

例如,在以下tutorial中,订阅有效负载显示在屏幕上:

代码语言:javascript
复制
curl -iX POST \
  --url 'http://localhost:1026/v2/subscriptions' \
  --header 'content-type: application/json' \
  --data '{
  "description": "Notify me of all product price changes",
  "subject": {
    "entities": [{"idPattern": ".*", "type": "Product"}],
    "condition": {
      "attrs": [ "price" ]
    }
  },
  "notification": {
    "http": {
      "url": "http://tutorial:3000/subscription/price-change"
    }
  }
}'

指的是在docker网络中称为tutorial的容器

代码语言:javascript
复制
  tutorial:
    image: fiware/tutorials.context-provider
    hostname: tutorial
    container_name: fiware-tutorial
    depends_on:
      - orion
    networks:
      default:
        aliases:
          - iot-sensors
          - context-provider
    expose:
      - 3000

碰巧的是,教程容器还将其内部端口3000暴露给运行它的机器的本地主机,以便用户可以查看它,但Orion只能通过docker网络上的主机名访问它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69023070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档