I'm working on a web app that involves managing users with a classic Ruby on Rails with MySQL setup.
This app also has chatbox elements. Socket.io seems like the right tool for the job, and I was hoping for some review on whether this process seems like a good idea:
Client sends chat message JSON to Rails controller.
Rails controller authenticates client and appends chat message to chat conversation JSON in MySQL server.
Rails controller sends response to client telling it MySQL server has been updated.
Client starts event on Socket.io Node server triggering it to send out updated chat conversation JSON to all clients (sockets).
EDIT: Steps 3 and 4 were updated. We go back to the client to speak to the Socket.io server after the Rails server because the Socket.io client-side library is good for triggering socket events. It also means not downloading an extra gem to mediate Rails-Socket.io communication. Let me know if this is a bad design choice.
This is the most complex project I've worked on, and I'm highly appreciative of any wisdom you guys could give me before I dive in.
I'm concerned about:
If I notify the Socket.io server to send out updated conversations the moment the user hits send, could it be possible that Rails won't finish authenticating and storing the new data in the MySQL server before Socket.io queries for it? Would it be awkward to delay Socket.io's query for a second after the user hits send? (I believe adding timers generally means I'm doing something wrong)
EDIT: I think I have the answer to the above after reading Mr. Yoshiji's comment. I'll send a response back to the client from the Rails server, and then the client will trigger the Socket.io server to update all other clients' chat. It will all be sequential with no race conditions or timer nonsense.
Would MongoDB or Redis be better than MySQL for chat conversation storage? I say MongoDB because the chat would all be JSON, and Redis seems to be used in tutorials and offer hooks for Socket.io, negating the above problem. On the downside, I'm unclear on what exactly Redis is, and I don't like the idea of adding a fourth server to this project.
Thank you for your help!
Related
Is it possible to build a realtime app using AngularJs with a mysql database?
I've been reading thousands of tutorials, but they are all focused on express, nodejs, etc.. didn't found any documentation on wheter it's possible or not. I tried to take a look at the socket.io docs, but still didn't found anything relevant to this question.
I didn't tried anything yet because of this. I use a webApp based on AngularJs on a apache server (local).
Where should i start to be able to build a real time app using these tools i have?
Do i really need to use a node/express server?
What are the main consideration i need to do before taking this step?
Is there any documentation i should read?
I need to do this real time because it involves product orders, call center, ticket system, etc.. So everytime there is a new ticket is opened/changed, new order arrives, etc.. I need to make the user aware of this, without the need to refresh the page.
Or if someone could give me a further explanation of this concept and how to get started, it will be great.
You can run angular on top of any backend, although most examples push towards REST. If you want your app to feel like a real time application, using WebSockets is a likely improvement.
WebSockets play nice with Angular, look at https://github.com/wilk/ng-websocket for example. A back-end in Node will work, but many other backend techs will do equally well.
Here is a decent tutorial using MySQL, NodeJS, and Angular: https://codeforgeek.com/2015/03/real-time-app-socket-io/
I recommend that you keep using a webserver like Apache (my personal preference is Nginx). You can proxy API and socket requests to Node, and serve static resources for the app from a folder.
Check out https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html if you stay with Apache. Check out http://nginx.org/en/docs/http/websocket.html is you go for nginx.
Without a webserver, you'll have to either:
serve your static resources with Node (polluting your server project with client code), or
work with different ports, risking the app becomes unusable in client environments, or
work with different domains, giving you a CORS head-ache.
Although I don't have much experience with Node, MySQL with Node.js should help you out a bit.
You'll want to move away from Apache if you want to do websocket stuff with Socket.io
Yes, it is possible to create a software with AngularJS in the front end and any other server side language that speaks to MySQL. Few months back I worked on a software with Java Spring Framework in the backend with MySQL database and AngularJS with bootstrap in the front end. You could start by following the MVC pattern, where your views can be served as AngularJS and your Controller can be in any server side code, with MySQL database.
I'm trying to create a real time web application with NodeJS with an MVC layout using the Express framework and MySQL as my back end data store.
The problem that I've run into is that I can't find any good examples or tutorials on how to use Socket.io (or any other web socket platform to pass information in real time from the database to the web application. The specific problem is getting any new update to MySQL on a specific table to pass that information to, so that if new information is added to the database by a second client connection it will update on the first client connection as soon as the information is added.
Does anyone have any ideas on how to get socket.io(or another websocket connection protocol) and mysql to work together to achieve this? Any code example's or pointing me to some websites that have documentation on this topic would be appreciated.
Thank you!
I want to receive a notification while Mysql database is updating and this notification should stop when the update finish (by adding "NEW"). I want to know the simplest way to do this .
Any idea please ?
Thanks
Yii, being a mere PHP framework running on the server, can not do such a thing. This is essential to client-server architecture. The server can not take the initiative to update the client.
The client (i.e. the user computer) can take the initiative. It can send a request to the server. Then, and only then, can the server respond to client.
You will need Javascript running on the client. The Javascript polls the server (via ajax) to see if the database is being updated. If javascript polls and finds that the server responds with: "database complete", then Javascript can add the 'NEW' logo.
This is question is about whether this will hypothetically work for a project I'm working on:
Flash .swf plays in browser
User sends SMS text message to SMS Server.
SMS Server updates MySQL Database value.
Flash connects to MySQL database and checks value.
Technically right now, I know I have to do research, but the biggest thing is "Flash needs to do something once it hits X amount of SMS text messages". Anything that I can cut out of that process would be great, but I think that's the best way.
The SMS part is a mystery to me, but after looking at another post, it seems like with http://www.twilio.com/ or something similar I can have a MySQL database receive SMS data.
Getting Flash to connect to MySQL I've heard is possible, but that's not really the part I'm worried about.
Suggestions or tips?
Flash cannot connect to MySQL directly.
It can "ask" a server side programming language to though.
Basically you use HTTP or AMF remoting to connect to a PHP class or file which in turn interrogates the database.
C# 2008
I have developed an application that need to connect to a web server in order to work. If the web server goes offline. The the app will have to be notified so that the user using the app can know what happened.
This application will be downloaded from the internet from our clients web site. So hundreds or thousands of users could have it.
I was thinking about pinging the web server maybe every 5 seconds. However, with 100's or 1000's apps would overload the web server.
Someone has told me about ESB would be right for this problem. The way I am thinking to use this, and I am not totally sure. Is to have every app to subscribe to the ESB. If the web server goes offline it will send a message to all the apps.
However, I understand that ESB is very big and complex and maybe this is overkill for my problem.
Am I understanding correctly.
If ESB is not the correct choice is there another design pattern I could use?
Many thanks
It sounds inappropriately out of scope to spec an ESB for this simple purpose. Why not just have the client machines figure it out as they periodically need to access the website? Instead of pinging the web server over and over, in the course of their normal activities they will need to access the web server for any normal reason, if they get an error response they can branch down the "web server is down" code path.
An ESB sounds like the wrong solution.
Two possibilities come to mind:
(1) If the user doesn't need to know they're offline in real-time, defer detection to usual error handling when you try and access the server.
(2) If you must know real time, use a small proxy at each client site so that only the proxies need to ping your server, not every desktop.