Project

General

Profile

Actions

Feature #993

open

Postgres NOTIFY

Added by Boris Nagaev over 13 years ago. Updated 2 months ago.

Status:
Review
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

Actions #1

Updated by Koen Deforche about 13 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

Actions #2

Updated by Matthias Van Ceulebroeck 3 months ago

  • Description updated (diff)
  • Assignee set to Romain Mardulyn
Actions #3

Updated by Romain Mardulyn 3 months ago

  • Status changed from New to InProgress
Actions #4

Updated by Romain Mardulyn 3 months ago

  • Status changed from InProgress to Review
  • Assignee deleted (Romain Mardulyn)
Actions #5

Updated by Matthias Van Ceulebroeck 2 months ago

  • Target version set to 4.12.0
Actions

Also available in: Atom PDF