-1

Clean Session supports persistence of messages. By default the value of Clean Session is true.

As we can set the Qos and retain flag value with the request payload as below:

docker run -it --rm --name mqtt-publisher --network \ fiware_default efrecon/mqtt-client pub -h mosquitto -m "c|1234" \ -t "/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs" -q 2 -r -d

can any one tell me how a client can set clean-session parameter as false? can we set this flag with request payload or there is other method for this ??

Naresh
  • 16,698
  • 6
  • 112
  • 113
Monika
  • 31
  • 6
  • We have no way of knowing what is running in that docker container, so no way to answer this question. How you set the clean session flag is entirely dependent on the client. Also the clean session flag has no real use for a publish only client. – hardillb Feb 19 '19 at 12:13

1 Answers1

2

The clean session flag is set when the MQTT client connects.

This is done in the CONNECT packet as part of the connect flags.

If you are using mosquitto_sub then it defaults to using a clean session for subscriptions. The -c or --disable-clean-session flag can be set to enable a persistent session.

The MQTT client id needs to be set when using this flag so the broker can track the subscriptions by client id. From https://mosquitto.org/man/mosquitto_sub-1.html:

-c, --disable-clean-session

Disable the 'clean session' flag. This means that all of the subscriptions for the client will be maintained after it disconnects, along with subsequent QoS 1 and QoS 2 messages that arrive. When the client reconnects, it will receive all of the queued messages.

If using this option, the client id must be set manually with --id

Community
  • 1
  • 1
Ben T
  • 4,656
  • 3
  • 22
  • 22
  • This is making an assumption that they are using the mosquitto cmd line tools in the random docker container, but also the example is about publishing, which doesn't really make sense to set clean session for. – hardillb Feb 19 '19 at 12:18