jdarling / MongoMQ

MongoMQ is a messaging queue built on top of Node.js and MongoDB's tailable cursors.
MIT License
90 stars 20 forks source link

Multiple listener instance in the same process #26

Open ltozi opened 9 years ago

ltozi commented 9 years ago

Hi, I noticed some problem instantiating multiple listener in the same node process. In practice, i created 4 listener for different topic but only one (the last one, queue4 of example) works correctly, while the others do not apper to dequeue messages.

Why is this not allowed?

Example listeners.js:

var queue1 = new MongoMQ({ databaseName: "localDb", autoStart: true, }); var queue2 = new MongoMQ({ databaseName: "localDb", autoStart: true, }); var queue3 = new MongoMQ({ databaseName: "localDb", autoStart: true, }); var queue4 = new MongoMQ({ databaseName: "localDb", autoStart: true, });

queue1.on("type1", callback1....); queue2.on("type2", callback2....); queue3.on("type3", callback3....); queue4.on("type4", callback4....);

Thanks, Luigi

jdarling commented 9 years ago

Sorry for the late response, been really busy and haven't had a bunch of time to go through my Github stuff recently.

That should work just fine, though the Mongo driver will actually pool those connections into a single connection.

I'm actually starting to use MongoMQ in a project again and will be updating it to the latest node-mongo-native driver (2.x.x), when I do I'll add in a test case for this.