Is there a Perl POE module for monitoring a database table for changes?

523 views Asked by At

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?

2

There are 2 answers

0
hobbs On

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.

0
MkV On

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.