Server: emqx
Client: php-mqtt/client 3.x
PHP≥7.4
- need
- The project needs to customize the offline and online of the subscription client
- code
$server = 'emqx server url'; $port = 1883; $clientId = 'sys_client'; $username = 'test'; $password = '12345678'; $topics='$SYS/brokers/+/clients/#';//Subscription client online and offline $mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId); $connectionSettings = (new \PhpMqtt\Client\ConnectionSettings) ->setUsername($username) ->setPassword($password); $mqtt->connect($connectionSettings, true); $mqtt->subscribe($topics, function ($topic, $message) { echo sprintf("Received message on topic [%s]: %s\n", $topic, $message); }, 0); $mqtt->loop(true); $mqtt->disconnect();
- Why is there an exception?
Received subscribe acknowledgement with invalid QoS values from the broker.
- How to solve it?
- Refer to the ACL documentation of EMQX for rule setting: https://www.emqx.io/docs/zh/v4.3/advanced/acl-file.html
- Default acl.conf
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}. {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}. {allow, all}.
- Modify acl.conf, for the sake of security, I only allow the specified ip subscription here
$SYS/brokers/+/clients/#
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}. #Specify ip subscription {allow, {ipaddr, "127.0.0.1"}, subscribe, ["$SYS/brokers/+/clients/#"]}. #Allow all clients to subscribe #{allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}. {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}. {allow, all}.
- Then, run it through the command line, it should not report an error
Similar Posts:
- Kafka Error: Error while executing topic command : Replication factor: 3 larger than available brokers: 0.
- Error accessing horizon after installing dashboard in openstack end of script output before headers: django.wsgi
- Easzlab/kubeasz ansible installation error [How to Solve]
- Kafka creates topic error: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 1 larger than available brokers: 0.
- [Solved] Emqx – /usr/lib/emqx/bin/cuttlefish: error while loading shared libraries: libtinfo.so.5: cannot ope
- [Solved] JMeter Use the JDBC linker Error: Unknown initial character set index ‘255’ received from server.initial client character
- Kafka production failed to send the message without response, or error while fetching metadata with correlation ID
- Problems of bad credentials, encoded password does not look like bcrypt in spring-cloud-oauth2 upgrade
- [Solved] ER_NOT_SUPPORTED_AUTH_Mode node connection database error
- Kafka startup error & problem solving