Closed gabrielmancini closed 2 years ago
Hi, the last will message will not be sent simply by disconnecting, it will be triggered only if the following conditions are met. When the client disconnects, a will message is sent to the relevant subscriber. Will Messages will be sent when:
Thanks, ref: https://www.emqx.com/en/blog/use-of-mqtt-will-message
there is a way to test last will on my broker using MQTTX?
@gabrielmancini Hi, you can try it in the following way:
In order to achieve the effect that MQTT connections are abnormally disconnected, we need to adjust EMQX's default ACL rules and related configuration items.
First, add the following ACL rule to etc/acl.conf
to deny local clients from connecting to the test topic. Note that this rule needs to be added before all the default ACL rules to ensure that it will work.
{deny, {ipaddr, "127.0.0.1"}, publish, ["test"]}. Then modify the zone.internal.acl_deny_action configuration in etc/emqx.conf to set it to disconnect the client when the ACL check denies: {deny, {ipaddr, "127.0.0.1"}, publish, ["test"}.
zone.internal.acl_deny_action = disconnect Once we have made these changes, we start EMQX.
Next, we create a new connection named demo in MQTT X, change the Host to localhost, select MQTT Version 5.0 in the Advanced section, and set the Session Expiry Interval to 10 to ensure that the session does not expire before the probate message is published.
Then in the Last Will and Testament section set Last-Will Topic to offline, Last-Will Payload to I'm offline, and Will Delay Interval (s) to 5.
Once the above settings are complete, we click the Connect button in the upper right corner to establish the connection.
Then we create a client connection named subscriber and subscribe to the offline topic.
Next, we go back to the demo connection and post a message with any content with Topic as a test, at this point, the connection will be disconnected, wait five seconds and we will see the subscriber connection receive a will message with the content I'm offline
.
awesome! its just woks on version 5?
sorry i closed accidentally
awesome! its just woks on version 5?
YES. You can select MQTT version 5.0 and test it again.
let me rephrase, Last will not work on 3.1?
let me rephrase, Last will not work on 3.1?
Oh, sorry. I did not read your question carefully, of course not, the Last Will can be used in all versions
Describe the problem you Confuse
i set the Last-Will Topic, Qos, Retain, Payload, connect and disconnect and the broker not send the last will message, i am using emqx on docker
More detail (optional)
my connection is not save and i am using the port 1883