是否有 Perl POE 模块用于监视数据库表的更改?
是否有任何 Wheel /POCO /Option 在 Perl 中使用 POE 模块执行此操作: 我想监视数据库表中更改的记录(删除/插入/更新)并对这些更改做出相应的反应。
如果是的话,可以提供一些代码或显示这一点的链接吗?
Is there any Wheel /POCO /Option to do this in Perl using the POE module:
I want to monitor a DB table for changed records (deleting /insert/ update) and react accordingly to those changes.
If yes could one provide some code or a link that shows this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道,但如果你真的勤奋的话,你可以写一个。我可以想到两种方法来做到这一点。
更好的第一点是:访问事务日志/复制源,例如 MySQL binlog。为其格式编写一个 POE::Filter ,然后使用 POE::Wheel::FollowTail 获取事件流,每个影响影响的语句一个数据库。然后您可以过滤数据以找到您感兴趣的内容。
不太好的主意:使用 EasyDBI 对表运行定期选择并查看发生了什么变化。如果您的数据很小,它可以工作(但它仍然容易出现计时问题);如果你的数据很大,这将是一个悲惨的失败。
Not that I'm aware of, but if you were really industrious you could write one. I can think of two ways to do it.
Better one first: get access to a transaction log / replication feed, e.g. the MySQL binlog. Write a POE::Filter for its format, then use POE::Wheel::FollowTail to get a stream of events, one for each statement that affects the DB. Then you can filter the data to find what you're interested in.
Not-so-good idea: using EasyDBI to run periodic selects against the table and see what changed. If your data is small it could work (but it's still prone to timing issues); if your data is big this will be a miserable failure.
如果您使用的是 PostgreSQL,您可以在表的更改上创建一个名为 NOTIFY 的触发器,并在客户端应用程序中打开一个连接并针对相同的通知执行 LISTEN。然后,您可以让 POE 侦听 DBD::Pg pg_socket 文件描述符上的文件事件。
或者,您可以创建一个 SQL 触发器来触发另一个文件或网络事件(写入文件、命名管道或套接字)并让 POE 侦听。
If you were using PostgreSQL, you could create a trigger on your table's changes that called NOTIFY and in your client app open a connection and execute a LISTEN for the same notification(s). You can then have POE listen for file events on the DBD::Pg pg_socket file descriptor.
Alternatively you could create a SQL trigger that caused another file or network event to be triggered (write to a file, named pipe or socket) and let POE listen on that.