Listen to database changes in MySQL [closed]

一世执手 提交于 2019-12-01 08:22:32
Shadow

Well, it is not entirely impossible to notify clients of changes done to the database, although there is no built-in solution for this.

In mysql you can create compiled user defined functions (UDFs) in C/C++. These can extend the functionality of mysql pretty much any way you want it - such as sending messages over the network. You can create your own UDF or use libraries available on mysqludf.org to send messages over the network. You could start with using the STOMP library on mysqludf.org to send STOMP messages. Since STOMP is language-agnostic, you can use it from .NET environment as well, see this SO topic (if search the Internet for .net STOMP server, then you will find more examples).

The client application has to implement a STOMP server that is able to receive the STOMP messages from the server.

In the database you need to create a subscription table that holds the information which client subscribes for what notifications and how to connect to it (IP address / host name and port number as a minimum).

You also need to create triggers on all those tables and events that you want to send notifications about.

I would also create a stored procedure or function that receives the modified data or the fact that certain table has been changed from the triggers, checks the subscription table, creates the STOMP message and then calls the compiled UDF that send the STOMP message to all the subscribed clients. The triggers would call this stored procedure or function instead of implementing all these functionality in each of the triggers.

The clients need to be modified to process the notifications and take further action or prompt the user.

Disclaimer: I do not claim that this is the most adequate and scalable solution for your particular case. However, this way you can implement a notification system on your own avoiding the need to poll your database.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!