← Back to team overview

mosquitto-users team mailing list archive

Re: Always received publish message even I restarted the server

 

Hi Neo,

As you've already figured out, the most likely cause for what you're
seeing is that there is a retained message set. It could also be down
to having a client with clean-session set false, but that would more
likely result in you getting a lot of messages at once when you
reconnected.

"mosquitto_pub -t my/topic -r -n" will *clear* a retained message for
a topic because it is sending a retained message with zero length
payload. If this does not appear to be clearing the retained message,
then something must be publishing retained messages to that topic.

You can use "mosquitto_sub -t my/topic -d" to determine whether a
message is retained or not. In the "Received PUBLISH" lines, you
should see either "r1" or "r0", which indicate the retained state. If
you see "r1", then the message was retained and is not fresh, i.e. it
could have been set any time ago. If you see "r0", then this means the
message has just been sent by another publisher. Even though you see
"r0", the message could still have had the retain flag set, but this
is not propagated to the subscribing client.

I hope that clears things up.

Cheers,

Roger


On Thu, May 9, 2013 at 4:00 PM, Neo Qing <neoqing@xxxxxxxxx> wrote:
> How can I check, whether did I publish a message as retained message? any
> command, I did not find it at man page.
>
>
> On Thu, May 9, 2013 at 4:22 PM, Neo Qing <neoqing@xxxxxxxxx> wrote:
>>
>> Hi,All:
>>   I'm using mosquitto (mosquitto version 1.1.3 (build date 2013-02-22
>> 19:49:18+0000)).
>>   and use node.js mqtt as client, and code shows below
>> var mqtt = require('mqtt');
>> console.log('test is started');
>> var receiveCount=0;
>> var subCount=0;
>> for(var i=0;i<1000;i++){
>> var client=mqtt.createClient(1883, 'myip');
>> client.connect({keepalive: 1000,client:'mqttClient'+i});
>> client.on('connack', function(packet) {
>> setInterval(function() {
>>  client.pingreq();
>> }, 1000);
>> });
>> console.log('connack i:'+i);
>> client.subscribe({topic:'/hello/world/demo',qos:1});
>> client.on('suback', function(packet) {
>> //console.log('subscribe success');
>> console.dir(packet);
>> subCount++;
>> console.log('subCount success:'+subCount);
>> });
>> }
>> client.on('publish', function(packet) {
>> //console.log('received message');
>> receiveCount++;
>> console.log('received message'+receiveCount);
>> console.log('received publis topic:'+packet.topic);
>> console.log('received publis message:'+packet.payload);
>> console.log(new Date());
>> });
>>
>> and I published a message with qos:1, I run the client couple times and
>> publish message couple time. After some while weird thing happened, anytime
>> when I run the client again, I always get the published message (topic is
>> '/hello/world/demo'). Then I restarted the mosiquitto server, but nothing is
>> changed, I always received the published message, even I did not publish
>> anything?
>> So here I need to know:
>> 1. How to stop these stuff, I don't want to receive that spam message, but
>> restart does not work
>> 2. Why does it happen? same client id causes this?
>> Thanks in advance!
>>
>> Neo
>>
>
>
> --
> 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
>


References