Rails + Pubnub Integration Architecture - ruby-on-rails

I am new to Pubnub and real-time application. I wrote some ruby application before and I am currently research an option to integrate pubnub into my rails application. I read pubnub docs already and have an basic architecture in my head but not quite sure if it is good or even feasible. I appreciate any opinions.
In the application, there will be a peer to peer chat window, and one person can talk to any person he wants.
1) Rails will not store any messages, and it will only stores which channels each person is subscribing to. In this case, since it is a peer-to-peer chat, a channel person publishing to is also the channel the person subscribing to. Rails will store all channels informations for all channels. And thats' it.
2) In client side, server will give each current_user the channels him/her subscribing/publishing to and using those channels, current_user can retrieve all history chats from pubnub server for channels he/she subscribes to.
This is what's in my head. Is there a better architecture implementation ? As far as I read in pubnub docs, they don't store channels for each unique user. Also, in terms of security, since everything will happen in the front-end and subscribe/publish key will be exposed to the browser. How secure is it ? Any drawbacks to this implementation ?
Thanks !!

Its very feasible... you can even get more creative after you nail down the basics. Here is a good chat with PubNub overview link:
http://www.pubnub.com/use-cases/chat/
Here you will find links to iOS and JS demo chat implementations.
Just for our Ruby fanatics, here is the link to a chat app purely using our Ruby SDK:
https://github.com/pubnub/ruby/blob/master/examples/translator.rb
The ruby app is pretty cool, as it lets people not only chat, but chat across multiple languages (via Bing translation API).
I'd say cut your teeth on these, and if you need further guidance, just shoot an email to support#pubnub.com, and we'll get you up and running with more tools and tricks specific to your use case.

Related

Any material about ejabberd internal Erlang API?

I have to create a chat app for my company, and, since I do programming in Elixir, my choice is ejabberd with Erlang/Elixir. I managed to install ejabberd as a dependency into my Elixir project, configured it, and I am also able to connect to it with some XMPP clients from the outside.
What I still need to achieve is to create a web based interface for the users where they can see the messages of certain conversations and where they also can push in text messages into ejabberd. Phoenix with it's channels are a perfect tool for this.
The missing parts I'm trying to figure out are some direct function calls into the ejabberd internals. Namely the followings are missing:
how can I do my own authentication in ejabberd with my already existing user base? (Erlang or Elixir)
how do I set the presence of a user with internal ejabberd function calls, when one uses it from Phoenix?
how can I tap into the message flow that goes trough ejabberd in order to broadcast those messages using Phoenix channels?
how can I send ejabberd messages from Erlang or Elixir in the name of a user?
I'm afraid ejabberd is poorly documented and it's mostly the source code that cen help me out. But I hope I'm wrong and there are some tutorials, blog posts, videos about the internals of it.
I would really appreciate any links to howtos, blog posts, example repos related to the internal Erlang API of ejabberd.
Here are what I already have, but this just scratches the surface:
elixir-sips-ejabberd-with-elixir-part-1
ejabberd-joins-the-elixir-revolution
the best source I ever found that explains how ejabberd works and what to do to plugin into its architecture is here:
http://anders.conbere.org (look at the links close to the bottom of the page)
Part1: http://anders.conbere.org/2008/07/16/building_ejabberd_modules_-_part_1_-_compiling_erlang.html
Part2: http://anders.conbere.org/2008/07/17/building_ejabberd_modules_-_part_2_-_generic_modules.html
Part3: http://anders.conbere.org/2008/07/31/building_ejabberd_modules_-_part_3_-_http_modules.html
Part4: http://anders.conbere.org/2008/08/06/building_ejabberd_modules_-_part_4_-_xmpp_bots.html
There is the developers guide in the official documentation: https://docs.ejabberd.im/developer/guide/
But full API is not documented, no.

Rails api PUSH chat message

I am developing a Rails application that will be exposed by API only. The application has a real time chat system which involves users submitting data to the server (via API calls), but what I want to push this data to other clients.
what is the best way to send data/message to other client?
Even knowing that your question will be closed, because at least you need to put some code (what you have now) I recently came across a blog post that will guide you in the right direction.
What you need is the new Rails 5 (still in beta) and the new component called ActionCable. Here you have the blog post describing how to use it. Also you have the DHH ActionCable examples.
Under the wood it uses websockets for full-duplex communications, ensuring your users will get the notifications.
Since you want an API based solution, you may need more work to get it with your frontend framework.

Load balancing with HAProxy for chat app by chat room

I'm making a chat app in Rails and using Node.js. I want to load balance with HAProxy, but it's important that all users in a specific chat room are on the same server. How can I achieve this? I've been searching Google, assuming the intel would be out there because this must be a common issue, but I can't find anything.
I think you should use session cookies, it's well described in this documentation : http://blog.haproxy.com/2012/03/29/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/

Twitter push notifications using Spring Social .NET

I'm using Spring.NET Twitter extensions in an application. Instead of querying in a loop for twit updates (pulling), I just want to listen to twits of interest (hashtags, # mentions, keywords or updates in timeline) and receive push notifications as they come. So I think the way to do it is to use an event model such as Observables, however, I can't find anything in the API to handle this nor any samples to demonstrate it. I would appreciate if anyone can put me in the right direction for this functionality. Thanks.
Spring Social Twitter only recently started supporting Twitter's streaming API. But that's for Java and your question is about SpringSocial.NET. I doubt that SpringSocial.NET has support for this yet. But I'll ping Bruno (the SpringSocial.NET project lead) and see if he can chime in here.
Until SpringSocial.NET supports Twitter's streaming API, your options are to continue polling (which is non-ideal due to rate limiting concerns) or to implement streaming support on your own. I'm sure Bruno wouldn't mind a pull-request to add streaming support to his project. :)
To be clear, SpringSocial.NET is not the same project as Spring Social and the two projects are only loosely related (in that I know who to email if there's ever a question about SpringSocial.NET).
Rx will just allow you to expose Push based API nicely. If the API does not support Push then you could use Rx to Fake Push by doing polling but expose it as if it was push (Observable.Interval or Schedulers etc).
You first will need to find how Twitter exposes Push based notifcations. If your Client (Spring.NET Twitter Ext) does not support this you are stuck with polling (via Rx or not).
It appears that you want to look at Twitter Streams API (https://dev.twitter.com/docs/streaming-apis)

Is combining Parse.com API with Pubnub a viable option for large scale Real-Time Messaging and obtaining the combined toolset?

Essentially combining Parse with Pubnub, Pusher or similar, Instead of building a custom backend from scratch.
I'll be working on a real-time messaging system with facebook login and file storage/sharing. In theory I could use a combination of Parse and something like Pubnub to cover backend requirements. Were:
Parse takes care of:
Login
File Storage
Push-notifications(closed app)
And Pubnub takes care of:
real
time delivery of messages...
Requirements:
I need a system that can extend to millions of users if needed and can be deployed quickly
In general a solution that will fit this criteria and specs.
Criteria:
Quick deployment by one or 2 developers.
Can expand to millions of users.
High reliability
Specs:
FB Login
Realtime Msg delivery
Push for closed app delivery
Shared file & image storage
Any feedback if this as a first stage deployment would work well and any pitfalls would be greatly appreciated.
I'm a little biased but check out StackMob (www.stackmob.com), with the StackMob Marketplace you get direct access to PubNub with no need to create a second account. There are also a lot of other great services in the marketplace to add functionality such as SendGrid.
All the features you are looking for are out of the box even the separate development and production accounts. Something you don't get with Parse. With a simple click of a button you can move Schemas and custom code from development to production.
We can certainly support the users you are talking about. We have 7 games from Atari on the platform and other big enterprise like Land O Lakes and Adidas Japan. We also have a great track record when it comes to reliability.
Sounds good, but 2 systems (Parse and PubNub) contradict your criteria Quick deployment by one or 2 developers.
There is reason to find one system which satisfies all your requirements.
You could loot at QuickBlox backend - your own cloud backend
It has 7 modules(sets of API) for different tasks. You may be interested in:
Users module - it has Facebook/Twitter login
Messages module - this is Push Notifications. It supports iOS, Android, BlackBerry, WindowsPhone push notifications
Content/CMS module - it allows to store/share/stream any type of files, any size (up to 5 TB!)
Chat module - realtime message delivery. QuickBlox Chat is a quick and reliable chat solution which combines benefits of scalable cloud hosted XMPP chat server, seamless Single Sign-On authorization via Users module, incoming IM / chat alerts via Push Notifications and file attachments via Content.
I recommend look at it, it also have lots of great features such custom API creation via Custom Objects module
Also, there is Enterprise solutions - QuickBlox this is white box, so you can deploy it to your own server and re-sale to other clients if you want
The short answer:
no.
The details:
Anyway you hash it, it's too expensive to setup a chat with any of these systems since their BaaS model is based on charging on a per number of calls basis.
I had to work out a lot of the logic my self using parse.com and now that I'm implementing an XMPP solution, the quantity of work is the same to get something working.
My alternative solution:
Use an open source xmpp server like ejabberd on something like AWS and then use one of the APIs to connect to it.
Contact me of you need more info on my experiences:
#andrescanella

Resources