【问题标题】:Eclipse Ditto - Create a MQTT Connection - fails with invalid json 400 responseEclipse Ditto - 创建 MQTT 连接 - 因无效 json 400 响应而失败
【发布时间】:2020-01-13 15:39:47
【问题描述】:

按照描述 here 和 MQTT 3.1.1 端点建立连接 Operating Devops Commands 以无效的 json 400 响应结束。甚至示例MQTT-Bidirectional 也被 400 拒绝。所以这就是为什么我在这里发布这个问题以获取提示我目前做错了什么以及我可以做些什么来帮助其他人在同一问题上运行。这是我的 curl 请求:

    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
            }]
        }
    }
}

【问题讨论】:

  • 你的 json 包在花括号里了吗?如果您像这样向您发送 json,则它不是有效的(如消息所述)。如果您在“{}”之间但您的完整内容。这应该是固定的。
  • 是的,如您所见(此处发布了完整的 json)以及 curl 请求。也许我的 curl 请求有问题,但我尝试了不同的选项,直到现在最终状态为 400
  • 好的,抱歉。由于格式化而错过了一些
  • 好的,仔细看看,2 个选项: - 您只能指定“源”或“目标”,不能同时指定两者。 - 来源/目标中的地址应采用以下格式:“地址”:“/topic/subtopic/#”,
  • 嗨,鲍勃,这是不正确的。连接可以同时具有:源和目标。

标签: json curl devops eclipse-ditto


【解决方案1】:

我认为您面临的问题与 curl 有关。 请在此处查看如何从文件发送 json 数据:https://stackoverflow.com/a/18614411/5058051

在您指定文件位置时,您的情况似乎缺少@

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多