mcollina / mqemitter-mongodb

MongoDB based MQEmitter
MIT License
18 stars 10 forks source link

[feat] Support mongodb replica set for mongo shared clusters support #19

Open robertsLando opened 4 years ago

robertsLando commented 4 years ago

Consider this question: https://developer.mongodb.com/community/forums/t/mongodb-pub-sub-using-tailable-cursors-in-nodejs-with-clusters/3027/4

This package could have some problems when using mongodb running on shared clusters.

In the question linked there are all the tips to use to make the support, maybe a new mqemitter packege could be created for that instead of making this supporting both

mcollina commented 4 years ago

Is this fixed?

robertsLando commented 4 years ago

Nope, this is an idea for a future development based on the question I linked in previous comment.

Tailable cursors may not be the best solution with MONGODB SHARED CLUSTERS

My PR has fixed mqemitter when using with NODEJS CLUSTERS.


Daniel - Software Engineer

Support me at: Github sponsors

On 23 Apr 2020, at 19:59, Matteo Collina notifications@github.com wrote:

 Is this fixed?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

mcollina commented 4 years ago

I don't know if it's possible to use something else on top of mongo. Go ahead and write another package if it would be a total rewrite of this one.

robertsLando commented 4 years ago

@mcollina Yes, sure :+1: Keep this open in the meanwhile

1977744311 commented 2 years ago

@mcollina @robertsLando I tried to start two node services to connect to the same mongo client. I found that the latest task will be consumed twice. Is this normal? How can I solve it?

robertsLando commented 2 years ago

Code snippet to reproduce the issue?

1977744311 commented 2 years ago

You can try to pull the code to execute locally git clone git@github.com:1977744311/issue-mq.git And you can do: npm install npm run issue Then you can see two services in pm2, You can visit the address of one of the services http://127.0.0.1:3000/api/emit, you can find the result of two emits in pm2 logs How should I avoid this, or is this package not supporting different instances connecting to the same database

robertsLando commented 2 years ago

I found that the latest task will be consumed twice. Is this normal? How can I solve it?

What do you mean with 'consumed twice' ? Do you mean that both services receive it once or that each service receive it twice?

1977744311 commented 2 years ago

both services receive it once

robertsLando commented 2 years ago

both services receive it once

That's the expected behaviour so. mqemitter is used exactly for that purpose, share messages across multiple instances. If you don't want all instances to receive a specific message you should create your own logic

1977744311 commented 2 years ago

both services receive it once

That's the expected behaviour so. mqemitter is used exactly for that purpose, share messages across multiple instances. If you don't want all instances to receive a specific message you should create your own logic

okey,thanks for your answer