我刚开始使用FIWARE。我在PopOs发行版上使用docker-compose下载了最新版本的on the website (v2)。我使用Postman发出请求(创建实体和订阅),并使用Laravel应用程序侦听来自FIWARE订阅的通知。但由于某些原因,今天,当我启动docker服务并开始发送请求时: FIWARE通知突然停止工作。
当我访问订阅端点时,FIWARE返回:
"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容器和本地机器之间有一些额外的配置吗?还是我做错了什么?
这是我的实体:
// 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"
}
}
}发布于 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中,订阅有效负载显示在屏幕上:
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网络上的主机名访问它。
https://stackoverflow.com/questions/69023070
复制相似问题