diff --git a/lib/persistence/levelup.js b/lib/persistence/levelup.js index 788fc46..a5a2d23 100644 --- a/lib/persistence/levelup.js +++ b/lib/persistence/levelup.js @@ -162,11 +162,10 @@ LevelUpPersistence.prototype.storeSubscriptions = function(client, done) { var now = Date.now(); if (!client.clean) { + // Issue #693 Object.keys(client.subscriptions).forEach(function(key) { - if (client.subscriptions[key].qos > 0) { - subscriptions[key] = client.subscriptions[key]; - subscriptions[key].ttl = that.options.ttl.subscriptions + now; - } + subscriptions[key] = client.subscriptions[key]; + subscriptions[key].ttl = that.options.ttl.subscriptions + now; }); this._clientSubscriptions.put(client.id, subscriptions, done); Object.keys(subscriptions).forEach(function(key) { diff --git a/lib/persistence/mongo.js b/lib/persistence/mongo.js index 2462393..4681a9b 100644 --- a/lib/persistence/mongo.js +++ b/lib/persistence/mongo.js @@ -183,9 +183,11 @@ MongoPersistence.prototype.storeSubscriptions = function(client, done) { var that = this; if (!client.clean) { - subscriptions = Object.keys(client.subscriptions).filter(function(key) { - return client.subscriptions[key].qos > 0; - }); + // Issue #693 + // subscriptions = Object.keys(client.subscriptions).filter(function(key) { + // return client.subscriptions[key].qos > 0; + // }); + subscriptions = Object.keys(client.subscriptions); steed.each(subscriptions, function(key, cb) { that._subscriptions.findAndModify({ diff --git a/lib/persistence/redis.js b/lib/persistence/redis.js index bc90851..e18d077 100644 --- a/lib/persistence/redis.js +++ b/lib/persistence/redis.js @@ -283,10 +283,9 @@ RedisPersistence.prototype.storeSubscriptions = function(client, cb) { var that = this; var subscriptions = {}; + // Issue #693 Object.keys(client.subscriptions).forEach(function(key) { - if (client.subscriptions[key].qos > 0) { - subscriptions[key] = client.subscriptions[key]; - } + subscriptions[key] = client.subscriptions[key]; }); this._client.get(clientSubKey, function(err, currentSubs){ diff --git a/test/persistence/abstract.js b/test/persistence/abstract.js index d3100b9..4085126 100644 --- a/test/persistence/abstract.js +++ b/test/persistence/abstract.js @@ -558,7 +558,7 @@ module.exports = function(create, buildOpts) { }); }); - it("should not store a QoS 0 subscription", function(done) { + it("should store a QoS 0 subscription", function(done) { var instance = this.instance; var client = { id: "my client id - 42", @@ -573,7 +573,7 @@ module.exports = function(create, buildOpts) { instance.storeSubscriptions(client, function() { instance.lookupSubscriptions(client, function(err, results) { - expect(results).to.eql({}); + expect(results).to.eql(client.subscriptions); done(); }); }); diff --git a/test/persistence/mongo_spec.js b/test/persistence/mongo_spec.js index 960e1c9..1ad7869 100644 --- a/test/persistence/mongo_spec.js +++ b/test/persistence/mongo_spec.js @@ -88,7 +88,7 @@ describe("mosca.persistence.Mongo", function() { var packet = { topic: "hello/42", qos: 0, - payload: 'someStringToTest', // not a buffer + payload: 'someStringToTest', // not a Buffer messageId: 42 };