Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using notify_listener - libpqxx

I'm trying to listen for notify events using libpqxx. I started by going off an example that extended pqxx::notify_listener.

#include <iostream>
#include <string>
#include <pqxx/pqxx>

class Foo : public pqxx::notify_listener {

public:
  Foo(pqxx::connection_base &c): pqxx::notify_listener(c, "listen") {}
  virtual void operator()(int id) { std::cout << "HERE!" << std::endl; }
};

int main(void) {
  // set up the listener
  pqxx::connection con("...secret...");
  Foo listener(con);

  // loop forever ...
}

I couldn't get this working though.

I tried switching the name parameter to
pqxx::notify_listener(c, "my_schema"),
pqxx::notify_listener(c, "listen my_schema") and some others.

I am creating the NOTIFY events manually via a pgAdmin. no matter what I do, the functor doesn't get executed.

like image 397
Ilia Choly Avatar asked Oct 10 '12 21:10

Ilia Choly


1 Answers

Do you call pqxx::connection_base::get_notifs() or pqxx::connection_base::await_notification() in the main loop?

If not, you need to.

like image 183
Daniel Vérité Avatar answered Sep 28 '22 03:09

Daniel Vérité