如何使用libpqxx接收PostgreSQL数据库的通知?

How to use libpqxx to receive notifications from the PostgreSQL database?

我正在编写 C++ 应用程序,它需要通过 libpqxx library. But it's tutorial doesn't include such use case. The notifications must be received on multiple channels. Also I'm using boost::asio 从 PostgreSQL 接收数据更改通知作为网络库,如果可能的话,对我来说最好使用 asio socket 类 具有通知事件的异步回调,而不是原始 BSD 样式套接字的轮询。有人可以为此提供示例代码或指向一些外部资源的链接以了解如何实现吗?

您需要从 pqxx::notification_receiver 派生的 class,参见 http://pqxx.org/devprojects/libpqxx/doc/4.0/html/Reference/a00208.html "Notifications and Receivers" 和 http://pqxx.org/devprojects/libpqxx/doc/4.0/html/Reference/a00062.htmlnotification_receiver 的 API 参考。