3

There are various old questions in the stackoverflow archives, like this one, which talk about cometd and friends. But I wanted to ask what the best technology is these days. Is it cometd?

I want to implement basic server-side push using ruby, preferably rails (though eventmachine or similar is possible). What is the best way to do this? For the purposes of this question, imagine I'm building a browser-based chat service. I use jQuery.

What do people use these days? Anyone know what kind of technology Facebook uses to push notifications to browsers? Priorities (in order) are:

  1. Ease of integrating with jQuery (or pure javascript) + Ruby-based server.
  2. Simplicity/elegance.
  3. Some degree of cross-browser compatibility (though not necessarily as old as IE 6).
  4. Performance.
Community
  • 1
  • 1
Peter
  • 114,224
  • 47
  • 167
  • 205

1 Answers1

1

I've experimented with socket.io and found it to work very well across ancient and modern browsers. With Node.js it's trivial to set up the server side for a messaging bus. If you are uncomfortable with Node.js I would recommend looking at eventmachine.

In order to scale the messaging service you are building you're server will need the ability to handle many long running connections at once. Traditional web servers aren't designed with this in mind.

Here is what I'd recommend. Create your base web application in Rails how you normally would. When you serve up a page, make sure socket.io on the client connects to your messaging server (this is going to be different than rails - node.js or eventmachine server). When you want to send a message to the client, your server-side rails app should send a message via the messaging server your client is listening to.

I've done this before using redis pub/sub, node.js, and socket.io. When I want to send a message from the rails server to the client, I publish a message to a channel in redis. Each client that is connected to the messaging service (built with node.js or eventmachine) will be subscribed to the channel and push the message to the client. The client can then deserialize the message and perform the necessary action.

bcurren
  • 74
  • 2