Dockerize FIWARE 无法通知服务
Dockerize FIWARE can't notify a service
我刚开始使用FIWARE。我在 PopOs 发行版上使用 docker-compose 下载了最新版本 on the website (v2)。
我正在使用 Postman 发出请求(创建实体和订阅)和一个 Laravel 应用程序来侦听来自 FIWARE 订阅的通知。但是由于某种原因,今天,当我启动 docker 服务并开始发送请求时:FIWARE 通知突然停止工作。
当我访问订阅端点 FIWARE 时 returns:
"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 请求,它 returns 200.
FIWARE docker 容器和本地机器之间有一些额外的配置?还是我做错了什么?
这是我的实体:
// http://{{orion}}/v2/subscription
{
"id": "movie",
"type": "movie",
"name": {
"type": "text",
"value": "movie name"
},
"gender": {
"type": "text",
"value": "drama"
}
}
我是这样订阅的:
// 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"
}
}
}
如果您使用 Docker,那么您需要考虑 http://localhost:8000/api/notifications
的实际含义。 localhost
将意味着 Orion 容器本身所经历的 localhost
。通常 Orion 在 1026 上监听,在 dockerized Orion 中没有在 8000 上监听,因此您的订阅失败。
如果您在同一 docker 网络和单独的容器中有另一个微服务 运行,您必须使用该容器的 hostname
(或 alias
或定义的 IP) 来描述通知 URL,而不是 localhost
.
例如,在下面的 tutorial 中,屏幕上显示了订阅负载:
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
的容器
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 网络上。
我刚开始使用FIWARE。我在 PopOs 发行版上使用 docker-compose 下载了最新版本 on the website (v2)。 我正在使用 Postman 发出请求(创建实体和订阅)和一个 Laravel 应用程序来侦听来自 FIWARE 订阅的通知。但是由于某种原因,今天,当我启动 docker 服务并开始发送请求时:FIWARE 通知突然停止工作。
当我访问订阅端点 FIWARE 时 returns:
"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 请求,它 returns 200.
FIWARE docker 容器和本地机器之间有一些额外的配置?还是我做错了什么?
这是我的实体:
// http://{{orion}}/v2/subscription
{
"id": "movie",
"type": "movie",
"name": {
"type": "text",
"value": "movie name"
},
"gender": {
"type": "text",
"value": "drama"
}
}
我是这样订阅的:
// 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"
}
}
}
如果您使用 Docker,那么您需要考虑 http://localhost:8000/api/notifications
的实际含义。 localhost
将意味着 Orion 容器本身所经历的 localhost
。通常 Orion 在 1026 上监听,在 dockerized Orion 中没有在 8000 上监听,因此您的订阅失败。
如果您在同一 docker 网络和单独的容器中有另一个微服务 运行,您必须使用该容器的 hostname
(或 alias
或定义的 IP) 来描述通知 URL,而不是 localhost
.
例如,在下面的 tutorial 中,屏幕上显示了订阅负载:
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
的容器
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 网络上。