← Back to team overview

mosquitto-users team mailing list archive

Re: Qos and receiving messages

 

Hello Jeroen,

Some information can be helpful from this link:
https://lists.launchpad.net/mosquitto-users/msg00012.html

A few comments:
    1.Set "retain" flag to True from publisher, so when your subscriber
online again, it will get the latest message (only one msg).
    2.If you don't want to miss anything, set "clean_session" to False, and
assign an unique id in your subscriber, set qos>0 from both publisher and
subscriber, then when your subscriber shows up again, it will receive all
the messages during its offline. (might need to set "max_queued_messages"
to a positive number in your mosquitto.conf)


Best,
/Chuan


On 11 July 2013 10:38, Jeroen Netten <jnetten@xxxxxxxxx> wrote:

> Hi all,
>
> I'm testing my Mosquitto setup and I want to make sure that messages that
> are sent to mosquitto will be picked up by a subscriber, even if a
> subscriber was disconnected for a while, but I cannot seem to get this to
> work, currently I listen to mosquitto (on ubuntu) using this command:*mosquitto_sub -d -q 1 -t hello/world
> *
>
> and I am sending periodic messages using the following python script:
>
> *import mosquitto*
> *import os*
> *import time*
> *
> *
> *broker = "127.0.0.1"*
> *port = 1883*
> *
> *
> *mypid = os.getpid()*
> *client_uniq = "pubclient_"+str(mypid)*
> *mqttc = mosquitto.Mosquitto(client_uniq)*
> *
> *
> *mqttc.connect(broker, port, 60, True)*
> *
> *
> *mqttc.publish("hello/world", "hi")*
> *
> *
> *while mqttc.loop() == 0:*
> *        msg = "test message " + time.ctime()*
> *        mqttc.publish("hello/world", msg, 1)*
> *        print "The following message was published: " + msg*
>
> My goal is that even if I disconnect the subscription for a while that all
> the messages that are sent to mosquitto  in the mean time will be saved and
> sent to a subscribing client as soon as it shows up again.
>
> I've tried to do this with qos=2 in the publish script, and that does seem
> to send the oldest message in the queue to the subscriber, but only at the
> interval at which new messages are arriving, and once I stop publishing,
> the subscriber stops receiving, even though there are still several
> messages which have not been received.
>
> Am I missing something obvious?
>
> Attached my .conf file.
>
> Kind Regards,
>
> Jeroen Netten
>
> --
> Mailing list: https://launchpad.net/~mosquitto-users
> Post to     : mosquitto-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~mosquitto-users
> More help   : https://help.launchpad.net/ListHelp
>
>

Follow ups

References