我是MQTT的新手,我想测试访问控制列表功能。 我正在使用mosquitto,MQTT v3.1代理进行测试。 我的ACL文件具有以下内容:
topic read $SYS/#
topic readwrite # <---- anyone without a username can publish to any topic
user test <---- only a client with username test can subscribe to the topic test
topic readwrite testTopic/#
这是我运行经纪人时得到的:
sudo mosquitto -c /etc/mosquitto/mosquitto.conf -v
1541640112: mosquitto version 1.4.8 (build date Wed, 05 Sep 2018 15:51:27 -0300) starting
1541640112: Config loaded from /etc/mosquitto/mosquitto.conf.
1541640112: Opening ipv4 listen socket on port 1884.
1541640112: Opening ipv6 listen socket on port 1884.
1541640113: New connection from ::1 on port 1884.
1541640113: New client connected from ::1 as 3 (c1, k60).
1541640113: Sending CONNACK to 3 (0, 0)
1541640113: Received SUBSCRIBE from 3
1541640113: testTopic (QoS 1)
1541640113: 3 1 testTopic
1541640113: Sending SUBACK to 3
1541640114: New connection from ::1 on port 1884.
1541640114: New client connected from ::1 as 1 (c1, k60, u'test').
1541640114: Sending CONNACK to 1 (0, 0)
1541640114: Received SUBSCRIBE from 1
1541640114: testTopic (QoS 1)
1541640114: 1 1 testTopic
1541640114: Sending SUBACK to 1
1541640115: New connection from ::1 on port 1884.
1541640115: New client connected from ::1 as 2 (c1, k60).
1541640115: Sending CONNACK to 2 (0, 0)
1541640115: Received PUBLISH from 2 (d0, q1, r0, m1, 'testTopic', ... (4 bytes))
1541640115: Sending PUBACK to 2 (Mid: 1)
1541640115: Sending PUBLISH to 3 (d0, q1, r0, m1, 'testTopic', ... (4 bytes))
1541640115: Received DISCONNECT from 2
1541640115: Client 2 disconnected.
1541640115: Received PUBACK from 3 (Mid: 1)
1541640118: Socket error on client 1, disconnecting.
1541640118: Socket error on client 3, disconnecting.
具有用户名“ test”的客户端订阅主题testTopic:
mosquitto_sub -t 'testTopic' -p 1884 -d -q 1 -u test -i 1
Client 1 sending CONNECT
Client 1 received CONNACK
Client 1 sending SUBSCRIBE (Mid: 1, Topic: testTopic, QoS: 1)
Client 1 received SUBACK
Subscribed (mid: 1): 1
使用没有用户名的客户端订阅主题testTopic:
mosquitto_sub -t 'testTopic' -p 1884 -d -q 1 -i 3
Client 3 sending CONNECT
Client 3 received CONNACK
Client 3 sending SUBSCRIBE (Mid: 1, Topic: testTopic, QoS: 1)
Client 3 received SUBACK
Subscribed (mid: 1): 1
Client 3 received PUBLISH (d0, q1, r0, m1, 'testTopic', ... (4 bytes))
Client 3 sending PUBACK (Mid: 1)
1724
和一个发布到主题testTopic的客户端:
mosquitto_pub -t 'testTopic' -m '1724' -p 1884 -d -q 1 -i 2
Client 2 sending CONNECT
Client 2 received CONNACK
Client 2 sending PUBLISH (d0, q1, r0, m1, 'testTopic', ... (4 bytes))
Client 2 received PUBACK (Mid: 1)
Client 2 sending DISCONNECT
问题是,为什么使用用户名测试的客户端未收到消息1724?
编辑: 我还尝试了在不更改ACL文件的情况下将发布主题和订阅主题更改为testTopic / foo,结果是相同的:
经纪人:
sudo mosquitto -c /etc/mosquitto/mosquitto.conf -v
1541967842: mosquitto version 1.4.8 (build date Wed, 05 Sep 2018 15:51:27 -0300) starting
1541967842: Config loaded from /etc/mosquitto/mosquitto.conf.
1541967842: Opening ipv4 listen socket on port 1884.
1541967842: Opening ipv6 listen socket on port 1884.
1541967844: New connection from ::1 on port 1884.
1541967844: New client connected from ::1 as 1 (c1, k60, u'test').
1541967844: Sending CONNACK to 1 (0, 0)
1541967844: Received SUBSCRIBE from 1
1541967844: testTopic/foo (QoS 1)
1541967844: 1 1 testTopic/foo
1541967844: Sending SUBACK to 1
1541967861: New connection from ::1 on port 1884.
1541967861: New client connected from ::1 as 3 (c1, k60).
1541967861: Sending CONNACK to 3 (0, 0)
1541967861: Received SUBSCRIBE from 3
1541967861: testTopic/foo (QoS 1)
1541967861: 3 1 testTopic/foo
1541967861: Sending SUBACK to 3
1541967875: New connection from ::1 on port 1884.
1541967875: New client connected from ::1 as 2 (c1, k60).
1541967875: Sending CONNACK to 2 (0, 0)
1541967875: Received PUBLISH from 2 (d0, q1, r0, m1, 'testTopic/foo', ... (4 bytes))
1541967875: Sending PUBACK to 2 (Mid: 1)
1541967875: Sending PUBLISH to 3 (d0, q1, r0, m1, 'testTopic/foo', ... (4 bytes))
1541967875: Received PUBACK from 3 (Mid: 1)
1541967875: Received DISCONNECT from 2
1541967875: Client 2 disconnected.
具有用户名“ test”的客户端订阅主题testTopic / foo:
mosquitto_sub -t 'testTopic/foo' -p 1884 -d -q 1 -u test -i 1
Client 1 sending CONNECT
Client 1 received CONNACK
Client 1 sending SUBSCRIBE (Mid: 1, Topic: testTopic/foo, QoS: 1)
Client 1 received SUBACK
Subscribed (mid: 1): 1
具有没有用户名的客户端的用户预订主题testTopic / foo:
mosquitto_sub -t 'testTopic/foo' -p 1884 -d -q 1 -i 3
Client 3 sending CONNECT
Client 3 received CONNACK
Client 3 sending SUBSCRIBE (Mid: 1, Topic: testTopic/foo, QoS: 1)
Client 3 received SUBACK
Subscribed (mid: 1): 1
Client 3 received PUBLISH (d0, q1, r0, m1, 'testTopic/foo', ... (4 bytes))
Client 3 sending PUBACK (Mid: 1)
1724
和一个发布到主题testTopic的客户端:
mosquitto_pub -t 'testTopic/foo' -m '1724' -p 1884 -d -q 1 -i 2
Client 2 sending CONNECT
Client 2 received CONNACK
Client 2 sending PUBLISH (d0, q1, r0, m1, 'testTopic/foo', ... (4 bytes))
Client 2 received PUBACK (Mid: 1)
Client 2 sending DISCONNECT
问题仍然存在,为什么具有用户名测试的客户端未收到消息1724?