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.
publish(index, collection, message, [options]);
Arguments | Type | Description |
---|---|---|
index | string | Index name |
collection | string | Collection name |
message | object | Message to send |
options | object | Query options |
options #
Additional query options
Option | Type (default) | Description |
---|---|---|
queuable | boolean ( true ) | Make this request queuable or not |
timeout | number ( -1 ) | Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely |
triggerEvents | boolean ( false ) | If set to true , will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop. Available since Kuzzle 2.31.0 |
Resolves #
A boolean indicating if the message was successfully published.
Usage #
const message = { realtime: 'rule the web' };
try {
await kuzzle.realtime.publish(
'i-dont-exist',
'in-database',
message
);
console.log('Success');
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)