using notify_listener - libpqxx
Asked Answered
P

1

7

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.

Photoactinic answered 10/10, 2012 at 21:13 Comment(0)
S
9

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

If not, you need to.

Snippy answered 10/10, 2012 at 23:55 Comment(1)
Nice catch. That was not obvious from the doxygen documentation.Ptolemy

© 2022 - 2024 — McMap. All rights reserved.