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.


publish(index, collection, message, [options]);

ArgumentsTypeDescription
index
string
Index name
collection
string
Collection name
message
object
Message to send
options
object
Query options

options #

Additional query options

OptionType
(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);
}