原生接口(interface)postgresql提供了如下命令:NOTIFY channel [ , payload ]
,其中payload为可变字符串。我使用库 pqxx
与数据库进行交互。它提供了notify_listener
接口(interface)。作为通知执行的回调只有一个参数 - id
。
这是我的代码:
class notif : public pqxx::notify_listener {
public:
notif(pqxx::connection_base &conn, const std::string &table, std::shared_ptr<notify_processor_t> pr) :
pqxx::notify_listener(conn, table), _table(table), _pr(pr) {}
notif(pqxx::connection_base &conn, const std::string &table) :
pqxx::notify_listener(conn, table), _table(table) {}
virtual void operator()(int id)
{
std::cout << "notification " << _table << std::endl;
if (_pr.get())
_pr->operator()();
}
private:
std::shared_ptr<notify_processor_t> _pr;
std::string _table;
};
如何使用提供的pqxx
接口(interface)获取payload
内容?
最佳答案
在libpqxx 4.0.1版本中发现如下:
// Obsolete notification receiver.
/** @deprecated Use notification_receiver instead.
*/
class PQXX_LIBEXPORT PQXX_NOVTABLE notify_listener
您应该使用notification receiver
类而不是notify_listener
关于postgresql pqxx notify_listener - 获取通知负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34453302/