Is there any Ruby/Rails library for sending PostgreSQL asynchronous notifications via WebSockets?
I need to notify a browser client for updates in a specific database table. I know this can be done with pub/sub APIs, but I'm looking for a Postgres only solution.
I've found a Python tutorial for this, but couldn't find one for Ruby. I need to implement this for production use, so a production-ready library and tutorial would be the best.
I don't know directly about any that does work with websockets, but queue_classic gem uses listen/notify in postgres for a message queueing. It's a good way to start looking how it can be done.
Related
Recently I've been looking for a solution to implement real-time updating web pages, for example, Twitter-like news feed or real-time chat. I've discovered some ways, as Pusher service, faye, and quite a lot of ruby gems, like private_pub or sync.
The problem is that this solutions don't seem to be a completely right way to follow. Pusher is rather expensive, and in fact I would not prefer to use other servie in my project. Faye seems insecure, and it is quite hard to implement security for it. Private_pub does the right thing, but last commit on github was in 2013 and in fact it is quite outdated.
All in all, ways that I have discovered do not seem to be professional-grade solutions for Rails startups. I have come up to the question whether I should completely switch to NodeJS or other technologies, or I can integrate NodeJS app inside a Rails one?
To sum up, is there such solution for Rails framework, or switch to another technologies is inevitable?
It may not help you right now, but at RailsConf last month DHH announced that Rails 5 will add support for websockets via a new library called ActionCable.
https://www.youtube.com/watch?v=oMlX9i9Icno
MessageBus might be a good fit. It's currently used in Discourse to implement live updates.
I'm also not sure what your security concerns about Faye are exactly. You should have no issues if everything is operating over HTTPS with proper CORS settings.
As for a mixed Node/Rails solution, you could push some list (e.g. post and list of those to be notified) on an update in the Rails app to a Redis instance. A Node app subscribed to Redis could then notify clients to make a request back to the Rails server for the latest updates.
I'm in a bit of a dilemma. I have Rails app which also uses Faye for websocket communication with Node.js server (used for chat and some other stuff). We also already use redis for some short lived data.
Now I want to implement some kind of real time notifications which will be stored in redis. I have two options:
I install faye gem and use faye client to directly send messages. But this required EventMachine. I tend to refuse adding a lot of new unnecessary stuff if it can be avoided.
I use redis pub/sub. Send data from rails to redis pub/sub and subscribe to the same channel in Node.js which will then publish those messages on faye channels.
Any suggestions on which approach to take? Or do you maybe have better solutions in mind?
I have been conflicted for a great deal of time in deciding how to update the app I am developing with notifications. In my app, users can post. I want to alert Users of new posts, just like facebook. However, given that Heroku does not support websockets and the like, deciding what to do has been tough. I DO NOT want to use pusher or pubnub as those services have outrageous prices.
In doing research, I learned about socket.io, which uses websockets if supported, then falls back on flash, or long polling to keep a connection to the server. This seems like the obvious choice for notifications b/c it will allow cross platform integration, it will be easy to implement websockets down the road, and its free.
I have been searching for a Rails 3+ Heroku supported socket.io gem, but I have read so many conflicting things that I am in great confusion. What are/is the best gem(s) to implement socket.io for Rails 3+ & Heroku?
We do not support long lived connections on heroku, so unfortunately using socket.io is not supported either. I would suggest that you use AJAX pulling (as Jakub Arnold suggests) to accomplish the same thing.
This may be sort of a newb-ish question. I know you can do this kind of thing in Node.js pretty easily, but I don't know what it's called and haven't had much luck with Google.
Basically, I am trying to build a simple tic-tac-toe server with Ruby on Rails. Players connect to each other, and moves are recorded and results processed live. If it was just having the user send messages to the server, that would be easily done with AJAX. However, I want to have the client wait and listen for the server to point out that the other player has made a move, and then automatically respond to that. I could do this by pinging the server with AJAX constantly, but there must be a better way. I feel like I'm missing some big technology that I haven't found yet just because I'm not entirely sure how to describe it or what it would be called.
Would I want to have the client connect directly to the server and maintain a live connection? If so, how would I do that? If not, what is the better way to do this? How do online games and stock tickers and streaming services provide their content to the client, and what tools does Rails give me to do something similar?
Check eventmachine in ruby
some links
https://github.com/eventmachine/eventmachine/wiki
http://20bits.com/article/an-eventmachine-tutorial
http://rubysource.com/introduction-to-event-machine
There is a faye and private_pub gem which makes things simpler .
There are railcasts available.
http://railscasts.com/episodes/260-messaging-with-faye
http://railscasts.com/episodes/316-private-pub
I recommend trying private_pub which is built on top on faye which uses eventmachine which can solve most of your questions
the pub/sub model helps to the client to subscribe to its channel
, so you can push updated to the channel which will be eventually passed to the client.
Your question and my answers
Q. Would I want to have the client connect directly to the server and maintain a live connection? If so, how would I do that?
A. You can use private_pub or faye to establish long connections and push data
also Check our later for pusher.com they provide services on commercial basis.
Q.How do online games and stock tickers and streaming services provide their content to the client, and what tools does Rails give me to do something similar?
A. AFAIK everyone uses some sort of push technology. pub/sub model. ruby has some gems available for such requirements, faye private_pub some of them..
For a commercial solution, check out Pusher, it does pretty much exactly what you want:
http://pusher.com/
For open source solutions, check out Faye (a pub/sub messaging server):
http://faye.jcoglan.com/
and some awesome railscasts explaining it:
http://railscasts.com/episodes/260-messaging-with-faye
http://railscasts.com/episodes/316-private-pub
I am build a real time web application using Ruby on Rails and Heroku seems to be the best option for hosting it.
I would prefer pushing new data to the user, when it becomes available, instead of pulling it by sending AJAX requests every few seconds.
Pusher seems to be suggested by Heroku for a such kind of job, but it has some limitations, brings additional costs, and makes you dependent on an external API.
Is there any other option to use WebSockets on Heroku?
If you wanna do websockets you need to use a different server besides rails. And since your on heroku you don't have the flexibility.
Optionally you can host a websockets enabled node server on an ec2 micro instance. Then in your rails app when you want to push -- do a request to the node server and the it will go to the clients.
If you only need one way communication try using Server Side events.
There are two options that you can use with Heroku aside from Pusher:
1) Like Eric Fode mentioned above, you could use SSE given you don't need two-way communication. There is a Heroku add-on which you could leverage for this: https://addons.heroku.com/eshq
2) There is another lesser known library called Faye which you could look into. It supports both Node.js and Ruby servers and it's based on the Bayeux Protocol
Heroku now has support for WebSockets: https://devcenter.heroku.com/articles/heroku-labs-websockets
While WebSockets isn't currently supported, apparently you can use Socket.io on Heroku, configuring it for long-polling.