Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket io channel notification for each user

I am an inexperienced developer, i just started learn node.js socket.io.

I want to make notification for each user if there's post in their wall or someone has replied(commented) to the user's post, just like in the fac*book/go*gle+ notification.

I follow the tutorial here http://www.codesizzle.com/node-js-and-socket-io/

I'm combining it with laravel4 and redis as the handler that publish the message/notif to redis, then nodejs will listen to redis and if there's post/event then send it using socket io to user's browser

Based on my understanding, example:

  1. userA posts something to userB
  2. userB receive the notif that says "user A has posted something on your wall"

to achieve this:

  • I need to make userB subscribes to its own channel, maybe using his id
  • then when userA post something, laravel4 will receive the ajax post data
  • laravel insert the post to MySQL and publish the user's id + his post to redis
  • after that nodejs will receive the event and publish it to userB's browser.

my question is in my statement "userB subscribes to its own channel, maybe using his id." this means userB will subscribe to channel maybe notif-channel-{userId} -> notif-channel-967 , if i have thousands of users then i will have thousands of different channel, maybe from notif-channel-1 until notif-channel-50000,

  1. will it become a problem?

  2. what is the best practice?

  3. does the flow already correct?

thankyou

note :sorry for the bad english.

UPDATE

After reading some more articles, i think i change the flow to:

  1. UserA posts somethingn on UserB's wall
  2. Then send ajax post to laravel so i can put the message/post into the db
  3. After that emit/push event to socketio thats working on nodejs server to handle the event and push it to userB's channel, tell userB that userA has posted something
  4. If success then notify UserA that his posts is successfull

notice that i dont involve redis in the above flow, any feedbacks?

like image 752
mohur Avatar asked Mar 23 '26 03:03

mohur


1 Answers

Using sockets to do this is a pretty complicated way of doing things. It's possible, but all you really need to do is add a timed post request from that page (client side) to check for new comments.

All you really need at that point is in the db. From, To, Date, Message.

With sockets you'd have to set up a channel for each user that has a 'wall', and anyone that is viewing a persons 'wall' will have to subscribe to it, and if it's a lot of people, you will have issues when you need to expand. That means using redis with sockets.io.

While that's 'cool' to do, it's overkill in my opinion.

like image 181
Chris Avatar answered Mar 24 '26 18:03

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!