aws iot - mosquitto_sub 未订阅

物联网 MQTT 蚊子 aws
2021-06-01 05:19:45

这是我的政策文件:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": [
        "arn:aws:iot:us-east-2:000000000000:client/sub",
        "arn:aws:iot:us-east-2:000000000000:client/pub"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "iot:Subscribe",
      "Resource": "arn:aws:iot:us-east-2:000000000000:topicfilter/org/cid/+/data"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Publish",
      "Resource": "arn:aws:iot:us-east-2:000000000000:topic/org/cid/sample/data"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Receive",
      "Resource": "arn:aws:iot:us-east-2:000000000000:topic/org/cid/sample/data"
    }
  ]
}

这是我的发布客户:

mosquitto_pub -h endpoint-ats.iot.us-east-2.amazonaws.com -p 8883 -i pub --cafile aws-iot-root-ca-1.pem --cert pub-certificate.pem.crt --key pub-private.pem.key -t /org/cid/sample/data -m 'Hello'

而且,这是我的订阅客户:

mosquitto_sub -h endpoint-ats.iot.us-east-2.amazonaws.com -p 8883 -i sub --cafile aws-iot-root-ca-1.pem --cert sub-certificate.pem.crt --key sub-private.pem.key -t /org/cid/+/data  -d

订阅永远不会通过;它不断重新连接。

Client sub sending CONNECT
Client sub received CONNACK
Client sub sending SUBSCRIBE (Mid: 1, Topic: /org/cid/+/data, QoS: 0)
Client sub sending CONNECT

证书正确附加到策略。

是否可以选择为每个客户端标识符定义发布/订阅设置?我错过了什么?

1个回答

两件事情:

  1. +作为外卡订阅兑现。文档

MQTT 通配符“+”不被视为策略中的通配符。尝试订阅与模式 foo/+/bar 匹配的主题过滤器,例如 foo/baz/bar 或 foo/goo/bar 失败并导致客户端断开连接。

  1. 主题字符串不应有前导斜杠。

因此,我将策略更改为具有确切的主题字符串,并在我的发布和子客户端中删除了前导斜杠。它现在有效。

:翻白眼: