Function publish

Synopsis

#include <lib/inc/drogon/PubSubService.h>

void publish(const std::string &topicName, const MessageType &message) const

Description

Publish a message to a topic. The message will be broadcasted to every subscriber.

Source

Lines 141-157 in lib/inc/drogon/PubSubService.h.

void publish(const std::string &topicName, const MessageType &message) const
{
    std::shared_ptr<Topic<MessageType>> topicPtr;
    {
        std::shared_lock<SharedMutex> lock(mutex_);
        auto iter = topicMap_.find(topicName);
        if (iter != topicMap_.end())
        {
            topicPtr = iter->second;
        }
        else
        {
            return;
        }
    }
    topicPtr->publish(message);
}





Add Discussion as Guest

Log in to DocsForge