简体   繁体   English

MySQL回调到Web应用程序

[英]MySQL callback to the web-app

I'm trying to figure out the best way possible to notify my web-application of database changes. 我试图找出最好的方式来通知我的Web应用程序数据库更改。 The way I'm doing it now, is that I've got separate MySQL table with a counter. 我现在的操作方式是,我有一个带有计数器的独立MySQL表。

Now, when some database action happens in table Foo, a trigger is adding up the counter. 现在,当表Foo中发生某些数据库操作时,触发器将添加计数器。 The web-app then polls every 5 seconds the server to check out, if something has happened (counter number has changed) and if so, refresh the data in app. 然后,Web应用程序每隔5秒轮询服务器一次,以检查是否发生了某些事情(计数器编号已更改),如果发生了这种情况,请刷新应用程序中的数据。

What I would like, is that I would be able to do callback/notify from MySQL to the server and from there to the web-app so that I don't need to poll the server frequently. 我想要的是,我将能够执行从MySQL到服务器以及从那里到Web应用程序的回调/通知,因此我不需要经常轮询服务器。 Is this possible somehow? 这有可能吗?

How does facebook, gmail send the real time notification? Facebook,Gmail如何发送实时通知? You can't notify your application directly from MySQL, but there are some solutions to save bandwith and load of your server. 您不能直接从MySQL通知您的应用程序,但是有一些解决方案可以节省带宽和服务器负载。

one way of handling this - would be to either implement the observer pattern yourself or simply use a pubsub messaging option (ZMQ/AMQ/RabbitMQ/Redis etc) - when the initial database action takes place (ensure that the transaction has committed), publish the message to the topic on the pubusb tool - your application can subscribe to the pubsub tool and receive messages when there is a DB change. 一种解决方法-是自己实施观察者模式,或者只是使用pubsub消息传递选项(ZMQ / AMQ / RabbitMQ / Redis等)-发生初始数据库操作(确保事务已提交)时,发布pubusb工具上有关该主题的消息-您的应用程序可以订阅pubsub工具,并在数据库发生更改时接收消息。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM