1

Sorry if this not the typical stackoverflow question. However, I believe that there is a "best-practice" answer out there and I am just to inexperienced with nodeJS to know it.

I am using the pusher api to receive some data. At the moment I am saving them in mysql and displaying them via express as a table and as a graph in my browser. However, my use case is slightly different.

When data arrives through the pusher api, I want update the browser view(table + graphs) of all connected clients.

I read a lot about socket.io and guess the "updating the clients" browser can be accomplished by using it. However, I am struggeling with the part of notifying my application that some new data has been inserted in my database.

I definitely need some form of Publish/Subscribe pattern in my app. Where the app subscribes to the database and pushes it via socket.io to the view.

Any recommendation how to implement in an easy way?

I appreciate your answer!

Carol.Kar
  • 4,581
  • 36
  • 131
  • 264
  • 1
    You are correct that this isn't really an SO question, but you are correct that a Pub/Sub pattern would work here. SO questions need to include what you have tried and have a specific question to ask. There are many tutorials out there for implementing Pub/Sub or using Socket.io – Jordan Kasper Dec 27 '14 at 22:31
  • @jakerella Thx for your answer! How would you implement Pub/Sub on a mysql db level?` – Carol.Kar Dec 27 '14 at 22:32

1 Answers1

2

Probably your easiest bet is to not listen for your mysql db being updated, but rather handle it as part of the pusher event handler. So when your pusher client receives an update, you would (at that point) both save to your mysql db as well as publish your own update to clients listening on socket.io connections.

Paul
  • 35,689
  • 11
  • 93
  • 122
  • Thx for your answer! Any suggestion how to communicate from the pusher script with the socket.io function? Both are, I guess asynchronous... – Carol.Kar Dec 28 '14 at 10:12
  • 1
    Sure, the socket.io homepage actually has an example that's almost exactly like you want, except that instead of listening to a tweet stream and emitting a tweet, you're listening to a pusher notification and emitting whatever custom event you want to have represent that. http://socket.io/ – Paul Dec 29 '14 at 04:11
  • Thx for your answer! Would you be so kind to point me to the tweet stream example. I couldn`t find it on the socket.io page. – Carol.Kar Dec 29 '14 at 12:37
  • 1
    It's right there on the page I linked you to. Middle of the page, sample code block on the left. – Paul Dec 30 '14 at 04:58