This class template implements a publish-subscribe pattern with multiple named topics.
More...
#include <drogon/PubSubService.h>
|
|
void | publish (const std::string &topicName, const MessageType &message) const |
| | Publish a message to a topic. The message will be broadcasted to every subscriber.
|
|
SubscriberID | subscribe (const std::string &topicName, const MessageHandler &handler) |
| | Subscribe to a topic. When a message is published to the topic, the handler is invoked by passing the topic and message as parameters.
|
| SubscriberID | subscribe (const std::string &topicName, MessageHandler &&handler) |
| | Subscribe to a topic. When a message is published to the topic, the handler is invoked by passing the topic and message as parameters.
|
| void | unsubscribe (const std::string &topicName, SubscriberID id) |
| | Unsubscribe from a topic.
|
|
size_t | size () const |
| | return the number of topics.
|
|
void | clear () |
| | remove all topics.
|
|
void | removeTopic (const std::string &topicName) |
| | Remove a topic.
|
| bool | isTopicEmpty (const std::string &topicName) const |
| | Check if a topic is empty.
|
template<typename MessageType>
class drogon::PubSubService< MessageType >
This class template implements a publish-subscribe pattern with multiple named topics.
- Template Parameters
-
| MessageType | The message type. |
◆ MessageHandler
template<typename MessageType>
Initial value:
std::function<void(const std::string &, const MessageType &)>
◆ isTopicEmpty()
template<typename MessageType>
Check if a topic is empty.
- Parameters
-
- Returns
- true means there are no subscribers.
-
false means there are subscribers in the topic.
◆ subscribe()
template<typename MessageType>
| SubscriberID drogon::PubSubService< MessageType >::subscribe |
( |
const std::string & | topicName, |
|
|
MessageHandler && | handler ) |
|
inline |
Subscribe to a topic. When a message is published to the topic, the handler is invoked by passing the topic and message as parameters.
- Parameters
-
| topicName | Topic name. |
| handler | The message handler. |
- Returns
- The subscriber ID.
◆ unsubscribe()
template<typename MessageType>
| void drogon::PubSubService< MessageType >::unsubscribe |
( |
const std::string & | topicName, |
|
|
SubscriberID | id ) |
|
inline |
Unsubscribe from a topic.
- Parameters
-
| topicName | Topic name. |
| id | The subscriber ID returned from the subscribe method. |
The documentation for this class was generated from the following file: