Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

when client reconnect with cleansession:false,receivced last online message #128

Closed
gongrui opened this issue May 1, 2014 · 14 comments
Closed

Comments

@gongrui
Copy link

gongrui commented May 1, 2014

mosca 0.20.3
mqtt 0.3.8

first run subscriber

subscriber.js

var mqtt = require('mqtt');
var client = mqtt.createClient(1883, 'localhost',{clean:false,encoding:'utf8', clientId: 'subscriber '});
client.on('connect', function(){
    client.subscribe('/foo',{qos:1});
});
client.on('message', function(topic, msg){
    console.log('Received Message:', topic, msg);
});

and run publish.js

var mqtt = require('mqtt');
var client = mqtt.createClient(1883, 'localhost',{encoding:'utf8', clientId: 'publish'});
client.on('connect', function(){
    client.publish('/foo', "123", {qos:1, retain:false});
    client.end();
});

the subscriber can receive message;
close the subscriber, run publish send offline message;
run subscriber second time, then subcriber can receive the offline message;

run publish send several online message.
close the subcriber again ,run publish send offline message,
this time when run subscriber to get offline message, it will receive the last all online message and offline message both.

when use Mosquitto 1.2.3 alone, havn't this issue

@mcollina
Copy link
Collaborator

mcollina commented May 1, 2014

Thanks for reporting! Are you using any specific database or broker?

@gongrui
Copy link
Author

gongrui commented May 1, 2014

Mongodb

@mcollina
Copy link
Collaborator

mcollina commented May 1, 2014

Weird, confirmed.

@mcollina
Copy link
Collaborator

mcollina commented May 2, 2014

Released as 0.21.0!

@gongrui
Copy link
Author

gongrui commented May 4, 2014

thx ,i'll test it again

@vyasashish
Copy link

I am also getting the same issue.Also what I observed is that lets say when the client was offline then some 10 messages were send.Now when the application comes online then only the first offline message will be sent.And when we again restart the client then the next offline message will be send.

Shouldn't the mosca server send all the offline message at once to client on reconnection?
Pardon me if I have understood the functionality in a wrong manner

@mcollina
Copy link
Collaborator

Can you please post some code to reproduce?

@ranjitnair77
Copy link

I'm able to reproduce this issue as well on mosca 0.23 using the publish.js and subscriber.js given above. Steps to reproduce:

  1. All sessions are not clean sessions.
  2. Publish a message, say with a QOS of 1 on a topic. No clients subscribed yet.
  3. Subscribe to the same topic. The subscriber gets the offline message.
  4. Stop and start the subscriber. The subscriber continues to receive the same offline message.
  5. The expected behaviour was that once a client receives an offline message, delivery of the same message does not occur.

Interestingly, this issue is not present if I publish to the test mosca instance hosted at test.mosca.io.

Mosca configuration

var redis = {
  type: 'redis',
  redis: require('redis'),
  db: 12,
  port: 6379,
  return_buffers: true, // to handle binary payloads
  host: "localhost"
};

var moscaSettings = {
  port: 1883,
  stats: false,
  backend: redis,
  persistence: {
    factory: mosca.persistence.Redis
  }
};

The publisher

var mqtt = require('mqtt');
var client = mqtt.createClient(1883, 'localhost',{encoding:'utf8', clientId: 'publish'});
client.on('connect', function(){
    client.publish('/foo', "456", {qos:1, retain:false});
    client.end();
});

The subscriber

var mqtt = require('mqtt');
var client = mqtt.createClient(1883, 'localhost',{clean:false,encoding:'utf8', clientId: 'subscriber '});

client.on('connect', function(){
    client.subscribe('/foo',{qos:1});
});

client.on('message', function(topic, msg){
    console.log('Received Message:', topic, msg);
});

@mcollina mcollina reopened this Aug 4, 2014
@mcollina
Copy link
Collaborator

mcollina commented Aug 4, 2014

Confirmed on Redis.

The instance on test.mosca.io is using LevelDB, which is not affected.

@mcollina
Copy link
Collaborator

mcollina commented Aug 4, 2014

This should be fixed in latest master. I would be grateful if you could give it a spin, otherwise I'll release it in the next few days as 0.23.2.

@ranjitnair77
Copy link

I've given it a spin and the fix works. Thanks !

@mcollina
Copy link
Collaborator

mcollina commented Aug 5, 2014

Released as 0.23.2.

@arvindsesha
Copy link

Not sure if this is the right Forum to post this issue, but anyways posting it to find some answers

I have a strange issue with a Mosquitto bridge on my android device connecting to Mosca on cloud.

The scenario is that I have a MQTT client connected to the Mosquitto bridge on the Android device and another client directly connected to the Mosca broker. When a message published through the mosca broker, the client directly connected to Mosca receives it only once [which is correct], but the client connected through the mosquitto bridge receives the same msg twice. The QOS is set to 1 at the bridge configuration and at the clients.

The mosquitto bridge configuration is as below

connection bridgetocloud
address Mosca-balancer-23232322323..elb.amazonaws.com:1883
topic mqtt/2/events/# both 1
bridge_attempt_unsubscribe false
keepalive_interval 30
start_type automatic
restart_timeout 1
try_private true

We also noticed that when the android Mosquitto is bridged with a Mosquitto set up on one of our servers, the msg delivery behaves correctly with only only one msg recieved at the MQTT client.

@mcollina
Copy link
Collaborator

Bridge mode is not supported #25

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants