moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

Message on connect: why not download only new message? #710

Open psummo opened 6 years ago

psummo commented 6 years ago

I have this simply backend for a chat in my app.

var mosca = require('mosca');
var mongoUrl = 'mongodb://localhost:27017/mqtt';
var ascoltatore = {
    //using ascoltatore
    type: 'mongo',
    url: mongoUrl ,
    pubsubCollection: 'ascoltatori',
    mongo: {}
};

var settings = {
    port: 1883,
    persistence: {
        factory: mosca.persistence.Mongo,
        url: mongoUrl,
    },
    backend: ascoltatore
};

var server = new mosca.Server(settings);

server.on('clientConnected', function(client) {
    console.log('client connected', client.id);

});

// fired when a message is received
server.on('published', function(packet, client) {
    console.log('Published', packet.payload);
});

server.on('ready', setup);

// fired when the mqtt server is ready
function setup() {
    console.log('Mosca server is up and running');
}

And I Publish and Subscribe from Client with QoS 1.

The problem is: On reconnect, client recive all message, also message that was already recived when client was online. Example CLIENT A & CLIENT B ONLINE CLIENT A --> SEND MESSAGE 1--> CLIENT A/B REVICE MESSAGE 1 CLIENT B --> DISCONNECT CLIENT A--> SEND MESSAGE 2--> CLIENT A REVICE MESSAGE 2 CLIENT B --> RE CONNECT --> CLIENT B RECIVE MESSAGE 1/2 But client B should recive only MESSAGE 2: correct?

mcollina commented 6 years ago

I would recommend to use http://npm.im/aedes http://npm.im/aedes-persistence-mongodb http://npm.im/mqemitter-mongodb.

psummo commented 6 years ago

It's the "new" mosca?

mcollina commented 6 years ago

Yes. Il giorno mar 12 dic 2017 alle 12:25 Pierluigi Summo < notifications@github.com> ha scritto:

It's the "new" mosca?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/mcollina/mosca/issues/710#issuecomment-351023813, or mute the thread https://github.com/notifications/unsubscribe-auth/AADL42YHReJJ_W_fkwnSejlnNJfkQb3Gks5s_mK3gaJpZM4Q-yRP .

psummo commented 6 years ago

I replace mosca with aedes but there's not a clear example for persistence and I have the same problem with offline message.