moscajs / mosca

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

Mongo persistent: subscription, retained and packets collections always empty #708

Closed robertsLando closed 6 years ago

robertsLando commented 6 years ago

I start Mosca with this configuration:

var server = require('http').createServer(app);

var ascoltatore = {
  type: 'mongo',
  url: 'mongodb://localhost:27017/mqtt',
  pubsubCollection: 'ascoltatori',
  mongo: {}
};

//mosca settings for packets persistence
var settings = {
  port: 1883,
  backend: ascoltatore,
  persistence: {
    factory: mosca.persistence.Mongo,
    url: 'mongodb://localhost:27017/mqtt'
  }
};

var broker = new mosca.Server(settings);
broker.attachHttpServer(server); //attach to a server for MQTT over WEBSOCKETS

I need to handle QoS 1 messages so each client has the cleanSession flag set to false and a fixed clientId. If I restart the server all clients reconnect but the broker doesn't 'remember' old subscriptions so they don't receive any packet. Is this a bug or have I missed something in my broker configuration?

My mqtt database has 4 collections:

ascoltatori keeps track of every subscribption/unsubscription, client connected/disconnected, packets published of every QoS and gets everyday bigger is there a way to limit it's size or the only limit is system storage size?

heyongchenghithub commented 6 years ago

How do you solve this?