Adjuntar un evento a MySQL desde Node.js (u otro)

I am designing an application that will run in a browser and have alerts pushed to it. I've already decided that to handle the mass of connections and all the so called reverse AJAX part of it with Node.js and This looks great to avoid constant polling and give me a real-time app except for one thing, how do I go about getting information out of a mysql database in real time?

I am envisioning something like an event handler whereby I can say something like on a row being inserted give me the data. I know this can be done with triggers but not how to do it.

¿Existe una forma correcta de hacer esto?

P.S. If I have to use something other than Node.js then this is no problem.



preguntado el 01 de febrero de 12 a las 14:02

You'd have much more luck using Redis since it has a publish/subscribe mechanism built in. Your other alternative is polling the database or writing a custom plugin function that would be executed via a database trigger, but that gets messy. -

Unfortunately the data is being pushed to a MySQL database and I have no control over that, if Redis can be set up to replicate from mysql that would work though. Thanks -

You can't automatically replicate MySQL to Redis. Especially since there's not a one-to-one mapping between the two data models. Database triggers are designed to update other data in the database, not to interact with external services. You may wish to look at the MySQL plugin API if you want to delve into C/C++ and write a function you can call from a trigger to do the heavy lifting. -

1 Respuestas

what if you try to use sys_exec(), UDF functions ? you'll be able to reach the node.js via mysql's triggers and some external script..

-- The mysql's Trigger fires a script (php or perl or whatever ) which contains your javascript node-client things.


Respondido 25 Jul 12, 00:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.