State-of-the-art HTTP push: jQuery, cometd?
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 开发者_如何学Pythonit 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:
- Ease of integrating with jQuery (or pure javascript) + Ruby-based server.
- Simplicity/elegance.
- Some degree of cross-browser compatibility (though not necessarily as old as IE 6).
- Performance.
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.
精彩评论