Project

General

Profile

Feature #993

Postgres NOTIFY

Added by Boris Nagaev about 10 years ago. Updated almost 10 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
09/20/2011
Due date:
% Done:

0%

Estimated time:

Description

Hello!

It would be great if Postgres connection class provided high-level notifying system, based on Postgres NOTIFY.

It could look like:

template<T>
WSignal<dbo::ptr<T> > listen();

template<T>
void notify(dbo::ptr<T>);

This can be used to notify other sessions (inside or outside this process or PC).

Applications seem to use not sqlite3, but postgres in production, and this notifying system seems useful for production applications.

Maybe these methods should be methods of Session or WServer...

This idea was inspired by WServer::post, which can be used for Dbo object update notifying.

BR

#1

Updated by Koen Deforche almost 10 years ago

Hey,

I like the suggestion. I think we need to implement it, it looks like a fun feature, and should be done by using WServer::post().

I think we need to add a utiliy class in Wt that implements this that implements this on behalf of one or more Dbo::Session classes (typically one per listening application), and internally keeps track of interested sessions/listeners. It needs a dedicated database connection, and thread (libpq's API for this is synchronous and requires polling, but they suggest you can select() on the connection). We should thus provide basic support for this in the SqlConnection class.

e.g.

class WDboReactor : public WObject
{
public:
  WDboReactor(SqlConnection *connection);

  void notify(const std::string& message);

  template <typename T>
  std::string encodeMessage(const std::string& event, const Wt::Dbo::ptr<T>& object);

  template <typename T>
  bool decodeMessage(const std::string& message, std::string& event, Wt::Dbo::ptr<T>& object);

  void addListener(WObject *object);
  void removeListener(WObject *object);

  Signal<WObject *object, std::string>& notified(); // emitted within the same application as the object lives, using WServer::post().
};

I would suggest to have both a Dbo::ptr<> and a string as parameters.

Regards,

koen

Also available in: Atom PDF