SDK
SDK Javascript v7.x
2

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.


Copied to clipboard!
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

Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely

Resolves #

A boolean indicating if the message was successfully published.

Usage #

Copied to clipboard!
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);
}