Eclipse Ditto - 创建 MQTT 连接 - 因 json 400 响应无效而失败
Eclipse Ditto - Create a MQTT Connection - fails with invalid json 400 response
按照描述 here 和 MQTT 3.1.1 端点建立连接
Operating Devops Commands end up in an invalid json 400 response. Even the example MQTT-Bidirectional 被 400 拒绝。所以这就是为什么我在这里发布这个问题以提示我目前做错了什么以及我可以做些什么来帮助其他人 运行同样的问题。这是我的卷曲请求:
gd@gd:~/ditto/mosquitto$ curl -X POST 'http://{ditto-url}/devops/piggyback/connectivity?timeout=10000' -u devops:foobar -H 'Content-Type: application/json' -d createMQTT_connection.json
{"status":400,"error":"json.invalid","message":"Failed to parse JSON string 'createMQTT_connection.json'!","description":"Check if the JSON was valid (e.g. on https://jsonlint.com) and if it was in required format."}
检查我的 json 文件的提示返回我的 json 是有效的。
这是我的 json 文件当前的样子:
{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:createConnection",
"connection": {
"id": "mqtt-example-connection-123",
"name": "mmqtt-example-connection-123",
"connectionType": "mqtt",
"connectionStatus": "open",
"failoverEnabled": true,
"uri": "tcp://{mqtt-broker-url}:1883",
"sources": [
{
"addresses": [
"{ditto-url}/#"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0,
"filters": []
}
],
"targets": [
{
"address": "{ditto-url}/{{ thing:id }}",
"topics": [
"_/_/things/twin/events"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0
}
]
}
}
}
有人知道为什么这个 json 无效吗?
感谢您的支持和提示来解决这个问题!
[编辑]
首先,“-f”对于 curl 请求更有意义:
curl -X POST -u devops:foobar 'http://{ditto-url}:8080/devops/piggyback/connectivity?timeout=10000' -f createMQTT_connection_1.json
curl: (22) The requested URL returned error: 400 Bad Request
curl: (6) Could not resolve host: createMQTT_connection_1.json
第二次更新json(结果如上所示)
{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:createConnection",
"connection": {
"id": "mqtt-example-connection-123",
"connectionType": "mqtt",
"connectionStatus": "open",
"failoverEnabled": true,
"uri": "tcp://{MQTT-Broker-url}:1883",
"sources": [{
"addresses": ["ditto-tutorial/#"],
"authorizationContext": ["nginx:ditto"],
"qos": 0,
"filters": []
}],
"targets": [{
"address": "ditto-tutorial/{{ thing:id }}",
"topics": [
"_/_/things/twin/events",
"_/_/things/live/messages"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0
}]
}
}
}
我认为您遇到的问题与 curl 相关。
请在此处查看如何从文件发送 json 数据:
您指定文件位置时似乎缺少 @
。
按照描述 here 和 MQTT 3.1.1 端点建立连接 Operating Devops Commands end up in an invalid json 400 response. Even the example MQTT-Bidirectional 被 400 拒绝。所以这就是为什么我在这里发布这个问题以提示我目前做错了什么以及我可以做些什么来帮助其他人 运行同样的问题。这是我的卷曲请求:
gd@gd:~/ditto/mosquitto$ curl -X POST 'http://{ditto-url}/devops/piggyback/connectivity?timeout=10000' -u devops:foobar -H 'Content-Type: application/json' -d createMQTT_connection.json
{"status":400,"error":"json.invalid","message":"Failed to parse JSON string 'createMQTT_connection.json'!","description":"Check if the JSON was valid (e.g. on https://jsonlint.com) and if it was in required format."}
检查我的 json 文件的提示返回我的 json 是有效的。
这是我的 json 文件当前的样子:
{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:createConnection",
"connection": {
"id": "mqtt-example-connection-123",
"name": "mmqtt-example-connection-123",
"connectionType": "mqtt",
"connectionStatus": "open",
"failoverEnabled": true,
"uri": "tcp://{mqtt-broker-url}:1883",
"sources": [
{
"addresses": [
"{ditto-url}/#"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0,
"filters": []
}
],
"targets": [
{
"address": "{ditto-url}/{{ thing:id }}",
"topics": [
"_/_/things/twin/events"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0
}
]
}
}
}
有人知道为什么这个 json 无效吗?
感谢您的支持和提示来解决这个问题!
[编辑] 首先,“-f”对于 curl 请求更有意义:
curl -X POST -u devops:foobar 'http://{ditto-url}:8080/devops/piggyback/connectivity?timeout=10000' -f createMQTT_connection_1.json
curl: (22) The requested URL returned error: 400 Bad Request
curl: (6) Could not resolve host: createMQTT_connection_1.json
第二次更新json(结果如上所示)
{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:createConnection",
"connection": {
"id": "mqtt-example-connection-123",
"connectionType": "mqtt",
"connectionStatus": "open",
"failoverEnabled": true,
"uri": "tcp://{MQTT-Broker-url}:1883",
"sources": [{
"addresses": ["ditto-tutorial/#"],
"authorizationContext": ["nginx:ditto"],
"qos": 0,
"filters": []
}],
"targets": [{
"address": "ditto-tutorial/{{ thing:id }}",
"topics": [
"_/_/things/twin/events",
"_/_/things/live/messages"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0
}]
}
}
}
我认为您遇到的问题与 curl 相关。 请在此处查看如何从文件发送 json 数据:
您指定文件位置时似乎缺少 @
。