Ahmet Ahmet -4 years ago 46
Java Question

Realtime Application with Nodejs MongoDB and JAVA as a backend

I am working on a web application that uses mongodb as the database. Data is inserted into this db via a Java Application and i want to somehow monitor/understand that the data is inserted from a nodejs application so that i can push some information to the clients via socket.io.

I know this is quite easy when we remove Java part from the equation and carry out the insertion via nodejs. But this is not the case for me; so i need pointers on mongodb - nodejs push kind of a thing..

It would be very nice if the solution remains only with Java, Nodejs and mongodb. But if some other 3rd party framework or technology (like mq) must be included i would be happy to hear that.

Answer Source

I'd suggest having the Java App let your front end (node) app know when it has changed something. That leaves the responsibility of knowing what has changed and how with the system making the changes. Watching the DB for changes sounds like a good idea, and will likely work but it's far more likely to cause you issues. Consider:

  • What data to watch?
  • What changes do you consider worthy of action?
  • What happens when you change how your data is updated?
  • How do you know when a change is atomic?

All these issues are at least mitigated if your front end is simply told what has changed and how, where to get the resource and when it happend.

How you tell your front end is up to you. Simple HTTP calls from Java to your front end is simple, if a little unreliable and unpredictable (load wise). A queue/notification service like Amazon SNS might be a little more robust.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download