drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::orm::DbListener Class Referenceabstract

Database asynchronous notification listener abstract class. More...

#include <drogon/orm/DbListener.h>

Public Types

using MessageCallback = std::function<void(std::string, std::string)>

Public Member Functions

virtual void listen (const std::string &channel, MessageCallback messageCallback) noexcept=0
 Listen to a channel.
virtual void unlisten (const std::string &channel) noexcept=0
 Stop listening to channel.

Static Public Member Functions

static DbListenerPtr newPgListener (const std::string &connInfo, trantor::EventLoop *loop=nullptr)
 Create a new postgresql notification listener.

Detailed Description

Database asynchronous notification listener abstract class.

Member Function Documentation

◆ listen()

virtual void drogon::orm::DbListener::listen ( const std::string & channel,
MessageCallback messageCallback )
pure virtualnoexcept

Listen to a channel.

Parameters
channelchannel name to listen
messageCallbackcallback when notification arrives on channel
Note
listen() can be called on the same channel multiple times. In this case, each messageCallback will be called when message arrives. However, a single unlisten() call will cancel all the callbacks.
If has connection issues, the listener will keep retrying until listen success. The listener will also re-listen to all channels after re-connection. However, if user passes an invalid channel string, the operation will fail with an error log without any other actions. (This behavior may change in future. A errorCallback may be added as a parameters.)

◆ newPgListener()

DbListenerPtr drogon::orm::DbListener::newPgListener ( const std::string & connInfo,
trantor::EventLoop * loop = nullptr )
static

Create a new postgresql notification listener.

Parameters
connInfoConnection string, the same as DbClient::newPgClient()
loopThe eventloop this DbListener runs in. If empty, a new thread will be created.
Returns
DbListenerPtr
nullptr if postgresql is not supported.

◆ unlisten()

virtual void drogon::orm::DbListener::unlisten ( const std::string & channel)
pure virtualnoexcept

Stop listening to channel.

Parameters
channelchannel to stop listening

The documentation for this class was generated from the following file: