moscajs / mosca

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

Duplicate message on regular topics (not wildcard) #644

Closed parfeon closed 7 years ago

parfeon commented 7 years ago

Setup: 1) two Mosca instances running (one on local and one on remote) 2) both instances configured backend to MongoDB which is running on remote (on the same where another Mosca instance is running) 3) configuration for both instances:

{
  id: 'mqtt',
  host: 'localhost', // for instance on remote there is server address
  port: 1883,
  allowNonSecure: true,
  maxInflightMessages: 10,
  stats: false,
  backend: {
    type: 'mongo',
    url: 'mongodb://<user>:<pwd>@<dbhost>:27017/<database>?auto_reconnect=true',
    pubsubCollection: '<collection>',
    mongo: {},
    ttl: { subscriptions: 10800000, packets: 10800000 }
  },
  persistence: {
    factory: mosca.persistence.Mongo,
    url: 'mongodb://<user>:<pwd>@<dbhost>:27017/<database>?auto_reconnect=true',
    pubsubCollection: '<collection>',
    mongo: {},
    ttl: { subscriptions: 10800000, packets: 10800000 }
  }
}  

<collection> - identical for both instances and between backend/persistence. In actual implementation, persistence configuration passed directly to mosca.persistence.Mongo, because I need access to lookupSubscriptions (I know it is private, but I need somehow figure out to which topics client has been subscribed during previous session). So, Mosca Server used with configuration w/o persistence key in it. 4) Using MQTTBox app create two clients with different identifiers. 5) ClientA subscribe on 'some/topic' 6) ClientB send message "fooboo" to 'some/topic' 7) ClientA receives two messages: "fooboo" (messageId: 1) and "fooboo" (messageId: 2).

Is there something missing in configuration because of which messages duplicated for both clients (receiver will receive two with different identifiers)?

P.S. Redis with same configuration duplicate messages as well.

Best regards, Sergey

parfeon commented 7 years ago

If backend set to local database and persistence to remote (remote database is shared between instances as backend) - no duplicate messages arrive. Which database should be shared with other broker instances?

Best regards, Sergey

mcollina commented 7 years ago

So, Mosca Server used with configuration w/o persistence key in it.

I do not understand.

You should not use lookupSubscriptions, but maybe it works for you.

I'm a bit lost. There are several tests that covers duplicates, so there might be something different going on.

Can you upload a full example that reproduces your issue? Ideally a single .js file with a MQTT.js client, or a unit test?

mcollina commented 7 years ago

Also: which version of Node.js and MongoDB?

parfeon commented 7 years ago

I give up. All of sudden duplicates stopped to arrive. No updates has been done to Redis DB and or NodeJS modules.

Best regards, Sergey