guys! I have rest api application. That app work with MongoDB, write some model example. How i can send some massage to all connection on SockJs server when i save some data in db?
Asked
Active
Viewed 215 times
0
-
1The far easier way to do it might be to set up a redis server as well, as redis has tools for doing this kind of broadcasting – ControlAltDel Aug 28 '14 at 17:07
-
Thanks for comment, but application must be without redis. – siavolt Aug 28 '14 at 17:12
-
MongoDB can't do this. You will have to implement this in your application server. The only workaround I could imagine which relies solely on MongoDB would be to have the clients constantly poll a collection which stores the latest events, but that would be really inefficient. – Philipp Aug 28 '14 at 17:24
1 Answers
0
I was able to do this using redis. You may refer to this article for guide
http://www.oditorium.com/ou/2014/02/implementing-a-pubsub-model-using-redis-nodejs-sockjs/
The way to do it is to subscribe all sockjs connection to a redis channel so you will have to create a redis subscriber client on every sockjs connection created but make sure that you unsubscribe and close the client once the sockjs connection is disconnected.

Gene Diaz
- 536
- 1
- 7
- 22