Database asynchronous notification listener abstract class.
More...
#include <drogon/orm/DbListener.h>
|
|
using | MessageCallback = std::function<void(std::string, std::string)> |
|
| 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 DbListenerPtr | newPgListener (const std::string &connInfo, trantor::EventLoop *loop=nullptr) |
| | Create a new postgresql notification listener.
|
Database asynchronous notification listener abstract class.
◆ listen()
| virtual void drogon::orm::DbListener::listen |
( |
const std::string & | channel, |
|
|
MessageCallback | messageCallback ) |
|
pure virtualnoexcept |
Listen to a channel.
- Parameters
-
| channel | channel name to listen |
| messageCallback | callback 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
-
- 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
-
| channel | channel to stop listening |
The documentation for this class was generated from the following file: