publish #
Sends a real-time message to Kuzzle. The message will be dispatched to all clients with subscriptions matching the index, the collection and the message content.
The index and collection are indicative and serve only to distinguish the rooms. They are not required to exist in the database
Note: real-time messages are not persisted in the database.
Signature #
void publish(
const std::string& index,
const std::string& collection,
const std::string& message);
void publish(
const std::string& index,
const std::string& collection,
const std::string& message,
const kuzzleio::query_options& options);
Arguments #
Arguments | Type | Description |
---|---|---|
index | const std::string& | Index name |
collection | const std::string& | Collection name |
message | const std::string& | JSON string representing a JSON payload |
options | kuzzleio::query_options* | Query options |
options #
Additional query options
Option | Type (default) | Description |
---|---|---|
queuable | bool ( true ) | If true, queues the request during downtime, until connected to Kuzzle again |
volatiles | const char* ( "{}" ) | JSON string representing subscription information, used in user join/leave notifications |
Exceptions #
Throws a kuzzleio::KuzzleException
if there is an error. See how to handle error.
Usage #
try {
std::string message = R"({ "realtime": "rule the web" })";
kuzzle->realtime->publish("i-dont-exist", "in-database", message);
std::cout << "Message successfully published" << std::endl;
} catch (kuzzleio::KuzzleException &e) {
std::cerr << e.what() << std::endl;
}