Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push data from rails app to clients

I'm working on a rails app that will primarily be exposed by an api to various mobile clients (iOS, android etc). The application involves users submitting data to the server (via api calls), but what I want to include is the ability to push this data down to other clients. The general concept is similar to a messaging app, where I submit a message to the server from me client and the receiver is pushed the message from the server.

The only method I know of at the moment is to constantly poll the server, but there must be better tech solutions than this. Any ideas?

like image 574
Jack Avatar asked Jan 14 '12 09:01

Jack


4 Answers

I would look at using a websocket within the page to push the updates.

You could implement this using Faye, which falls back to long polling and other work-arounds for browsers without websocket support. Faye has a pure-ruby implementation, so you could probably work out access to your model layer.

Edit:

Also, this is a project that combines Faye with Rails. It is fairly new, but might do what you want. Faye-Rails

like image 117
ebeland Avatar answered Oct 16 '22 04:10

ebeland


You should check out http://www.pusher.com

Pusher is a hosted API for quickly, easily and securely adding scalable realtime functionality to web and mobile apps.

If you need self-hosted solution, then you should check out slanger gem https://github.com/stevegraham/slanger which is server implementation for pusher client libraries. When you feel you need hosted solution, you just change URL's.

Slanger is an open source server implementation of the Pusher protocol written in Ruby. It is designed to scale horizontally across N nodes and to be agnostic as to which Slanger node a subscriber is connected to, i.e subscribers to the same channel are NOT required to be connected to the same Slanger node. Multiple Slanger nodes can sit behind a load balancer with no special configuration. In essence it was designed to be very easy to scale.

like image 32
Ahmed Al Hafoudh Avatar answered Oct 16 '22 02:10

Ahmed Al Hafoudh


Ruby has it's own event-processing library, implemented like a gem:

https://github.com/eventmachine/eventmachine

Maybe it helps you

like image 25
alexkv Avatar answered Oct 16 '22 03:10

alexkv


I prefer event machine over any other solution. It is somewhat more complicated that faye but you can write way more sophisticated code using event machine.

You might wanna check this peepcode screencast on event machine

like image 1
VivekVarade123 Avatar answered Oct 16 '22 03:10

VivekVarade123