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

Commit

Permalink
Merge pull request #694 from mitsos1os/issue-693
Browse files Browse the repository at this point in the history
Also persist QoS 0 subscriptions when clean flag false
  • Loading branch information
mcollina authored Oct 30, 2017
2 parents 1332f1a + 9d7c706 commit 5277cca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
7 changes: 3 additions & 4 deletions lib/persistence/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions lib/persistence/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 2 additions & 3 deletions lib/persistence/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions test/persistence/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/persistence/mongo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down

0 comments on commit 5277cca

Please sign in to comment.