Constructor

This is the main entry point to communicate with Kuzzle.
Each instance represent a connection to Kuzzle with specific options.

Signature

Kuzzle(std::string host, kuzzleio::options *options = nullptr)

Arguments

Argument Type Description Required
host std::string The target Kuzzle host yes
options options* Kuzzle connection configuration yes

hostname

The Kuzzle host to connect to.
Can be a hostname or an IP address.

options

Option Type Description Default Required
auto_queue boolean Automatically queue all requests during offline mode false no
auto_reconnect boolean Automatically reconnect after a connection loss true no
auto_replay boolean Automatically replay queued requests on a reconnected event false no
auto_resubscribe boolean Automatically renew all subscriptions on a reconnected event true no
offline_mode enum Mode Offline mode configuration MANUAL no
queue_ttl unsigned Time a queued request is kept during offline mode, in milliseconds 120000 no
queue_max_size unsigned long Number of maximum requests kept during offline mode 500 no
replay_interval unsigned long Delay between each replayed requests, in milliseconds 10 no
reconnection_delay unsigned long number of milliseconds between reconnection attempts 1000 no
volatile std::string (json) Common volatile data, will be sent to all future requests - no

Getter & Setter

The properties can be writable.
For example, you can read the volatile property via getVolatile() and set it via setVolatile().

Property name Type Description Availability
autoReplay boolean Automatically replay queued requests on a reconnected event Set
jwt std::string Token used in requests for authentication. Get
volatile std::string (json) Common volatile data, will be sent to all future requests Get/Set

Notes:

  • multiple methods allow passing specific volatile data. These volatile data will be merged with the global Kuzzle volatile object when sending the request, with the request specific volatile taking priority over the global ones.
  • the queueFilter property is a function taking a query_object as an argument. This object is the request sent to Kuzzle, following the Kuzzle API format
  • if queueTTL is set to 0, requests are kept indefinitely
  • The offline buffer acts like a first-in first-out (FIFO) queue, meaning that if the queueMaxSize limit is reached, older requests are discarded to make room for new requests
  • if queueMaxSize is set to 0, an unlimited number of requests is kept until the buffer is flushed
  • the offlineQueueLoader must be set with a function, taking no argument, and returning an array of objects containing a query member with a Kuzzle query to be replayed, and an optional cb member with the corresponding callback to invoke with the query result
  • updates to autoReconnect, reconnectionDelay and sslConnection properties will only take effect on next connect call

Return

A Kuzzle instance.

Usage

kuzzleio::options options = KUZZLE_OPTIONS_DEFAULT;
options.auto_resubscribe = false;

kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle("kuzzle", &options);

copts := types.NewOptions()
copts.SetPort(7512)
copts.SetAutoResubscribe(false)
conn := websocket.NewWebSocket("kuzzle", copts)

k, _ := kuzzle.NewKuzzle(conn, nil)

Options options = new Options();
options.setAutoResubscribe(false);

Kuzzle kuzzle = new Kuzzle("kuzzle", options);

const options = {
  host: 'localhost',
  autoResubscribe: false
};

// Instantiate the SDK with an embedded protocol
const kuzzleWS = new Kuzzle('websocket', options);

// Instantiate the SDK with a custom protocol
const customProtocol = new MyCustomProtocol();
const kuzzleCustom = new Kuzzle(customProtocol, options);

NewKuzzle(protocol connection.Connection) (*Kuzzle, error)

Arguments

Argument Type Description Required
protocol connection.Connection The protocol used by the SDK instance yes

protocol

A Protocol is a structure implementing the connection.Connection interface. The available protocols are:

  • websocket.Websocket

The protocol must be instantiated and passed to the constructor. It takes the following arguments:

Argument Type Description Required
host string Kuzzle hostname to connect to yes
options types.Options Kuzzle connection configuration yes

The options parameter of the protocol constructor has the following properties.
You can use standard getter/setter to use these properties.

Option Type Description Default Required
autoQueue boolean Automatically queue all requests during offline mode false no
autoReconnect boolean Automatically reconnect after a connection loss true no
autoReplay boolean Automatically replay queued requests on a reconnected event false no
autoResubscribe boolean Automatically renew all subscriptions on a reconnected event true no
offlineMode int Offline mode configuration types.Manual no
port int Target Kuzzle port 7512 no
queueTTL int Time a queued request is kept during offline mode, in milliseconds 120000 no
queueMaxSize int Number of maximum requests kept during offline mode 500 no
replayInterval Duration Delay between each replayed requests, in milliseconds 10 no
reconnectionDelay Duration number of milliseconds between reconnection attempts 1000 no
sslConnection boolean Switch Kuzzle connection to SSL mode false no
volatile VolatileData Common volatile data, will be sent to all future requests - no

Getter & Setter

These properties of the Kuzzle struct can be writable.
For example, you can read the volatile property via getVolatile() and set it via setVolatile().

Property name Type Description Availability
autoQueue boolean Automatically queue all requests during offline mode Get/Set
autoReconnect boolean Automatically reconnect after a connection loss Get
autoReplay boolean Automatically replay queued requests on a reconnected event Get/Set
autoResubscribe boolean Automatically renew all subscriptions on a reconnected event Get/Set
host string Target Kuzzle host Get
port int Target Kuzzle port Get
jwt string Token used in requests for authentication. Get/Set
offlineQueue QueryObject Contains the queued requests during offline mode Get
offlineQueueLoader OfflineQueueLoader Called before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queue Get/Set
queueFilter QueueFilter Called during offline mode. Takes a request object as arguments and returns a boolean, indicating if a request can be queued Get/Set
queueMaxSize int Number of maximum requests kept during offline mode Get/Set
queueTTL Duration Time a queued request is kept during offline mode, in milliseconds Get/Set
replayInterval Duration Delay between each replayed requests Get/Set
reconnectionDelay Duration Number of milliseconds between reconnection attempts Get
sslConnection boolean Connect to Kuzzle using SSL Get
volatile VolatileData Common volatile data, will be sent to all future requests Get/Set

Notes:

  • multiple methods allow passing specific volatile data. These volatile data will be merged with the global Kuzzle volatile object when sending the request, with the request specific volatile taking priority over the global ones.
  • the queueFilter property is a function taking a QueryObject as an argument. This object is the request sent to Kuzzle, following the Kuzzle API format
  • if queueTTL is set to 0, requests are kept indefinitely
  • The offline buffer acts like a first-in first-out (FIFO) queue, meaning that if the queueMaxSize limit is reached, older requests are discarded to make room for new requests
  • if queueMaxSize is set to 0, an unlimited number of requests is kept until the buffer is flushed
  • the offlineQueueLoader must be set with a function, taking no argument, and returning an array of objects containing a query member with a Kuzzle query to be replayed, and an optional cb member with the corresponding callback to invoke with the query result
  • updates to autoReconnect, reconnectionDelay and sslConnection properties will only take effect on next connect call

Return

A Kuzzle struct and an error struct.
The error struct is nil if everything was ok.

Usage

In a first step, you have to create a new connection.Connection and pass it to the constructor.
By now the only connection available is websocket.Websocket.

kuzzleio::options options = KUZZLE_OPTIONS_DEFAULT;
options.auto_resubscribe = false;

kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle("kuzzle", &options);

copts := types.NewOptions()
copts.SetPort(7512)
copts.SetAutoResubscribe(false)
conn := websocket.NewWebSocket("kuzzle", copts)

k, _ := kuzzle.NewKuzzle(conn, nil)

Options options = new Options();
options.setAutoResubscribe(false);

Kuzzle kuzzle = new Kuzzle("kuzzle", options);

const options = {
  host: 'localhost',
  autoResubscribe: false
};

// Instantiate the SDK with an embedded protocol
const kuzzleWS = new Kuzzle('websocket', options);

// Instantiate the SDK with a custom protocol
const customProtocol = new MyCustomProtocol();
const kuzzleCustom = new Kuzzle(customProtocol, options);

Kuzzle(String host)
Kuzzle(String host, Options options)

Arguments

Argument Type Description Required
host String The target Kuzzle host yes
options Options Kuzzle connection configuration yes

host

The Kuzzle host to connect to.
Can be a hostname or an IP address.

options

Option Type Description Default Required
autoQueue boolean Automatically queue all requests during offline mode false no
autoReconnect boolean Automatically reconnect after a connection loss true no
autoReplay boolean Automatically replay queued requests on a reconnected event false no
autoResubscribe boolean Automatically renew all subscriptions on a reconnected event true no
offlineMode Mode Offline mode configuration MANUAL no
queueTTL int Time a queued request is kept during offline mode, in milliseconds 120000 no
queueMaxSize int Number of maximum requests kept during offline mode 500 no
replayInterval Duration Delay between each replayed requests, in milliseconds 10 no
reconnectionDelay Duration number of milliseconds between reconnection attempts 1000 no
sslConnection boolean Switch Kuzzle connection to SSL mode false no
volatile VolatileData Common volatile data, will be sent to all future requests - no

Getter & Setter

The properties can be writable.
For example, you can read the volatile property via getVolatile() and set it via setVolatile().

Property name Type Description Availability
autoReplay boolean Automatically replay queued requests on a reconnected event Set
jwt String Token used in requests for authentication. Get
volatile String (json) Common volatile data, will be sent to all future requests Get/Set

Notes:

  • multiple methods allow passing specific volatile data. These volatile data will be merged with the global Kuzzle volatile object when sending the request, with the request specific volatile taking priority over the global ones.
  • the queueFilter property is a function taking a QueryObject as an argument. This object is the request sent to Kuzzle, following the Kuzzle API format
  • if queueTTL is set to 0, requests are kept indefinitely
  • The offline buffer acts like a first-in first-out (FIFO) queue, meaning that if the queueMaxSize limit is reached, older requests are discarded to make room for new requests
  • if queueMaxSize is set to 0, an unlimited number of requests is kept until the buffer is flushed
  • the offlineQueueLoader must be set with a function, taking no argument, and returning an array of objects containing a query member with a Kuzzle query to be replayed, and an optional cb member with the corresponding callback to invoke with the query result
  • updates to autoReconnect, reconnectionDelay and sslConnection properties will only take effect on next connect call

Return

A Kuzzle instance.

Usage

kuzzleio::options options = KUZZLE_OPTIONS_DEFAULT;
options.auto_resubscribe = false;

kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle("kuzzle", &options);

copts := types.NewOptions()
copts.SetPort(7512)
copts.SetAutoResubscribe(false)
conn := websocket.NewWebSocket("kuzzle", copts)

k, _ := kuzzle.NewKuzzle(conn, nil)

Options options = new Options();
options.setAutoResubscribe(false);

Kuzzle kuzzle = new Kuzzle("kuzzle", options);

const options = {
  host: 'localhost',
  autoResubscribe: false
};

// Instantiate the SDK with an embedded protocol
const kuzzleWS = new Kuzzle('websocket', options);

// Instantiate the SDK with a custom protocol
const customProtocol = new MyCustomProtocol();
const kuzzleCustom = new Kuzzle(customProtocol, options);

/**
 * @param {string|Protocol} protocol
 * @param {object} [options]
 * @returns {Kuzzle}
 */
Kuzzle(protocol, options = {})

Arguments

Argument Type Description Required
protocol string or Protocol The protocol used by the SDK instance yes
options object Kuzzle connection configuration yes

protocol

The protocol used to connect to the Kuzzle instance.
It can be:

  • a string for embedded protocols : http, websocket or socketio
  • a custom Protocol object

options

Option Type Description Default Required
autoQueue boolean Automatically queue all requests during offline mode false no
autoReconnect boolean Automatically reconnect after a connection loss true no
autoReplay boolean Automatically replay queued requests on a reconnected event false no
autoResubscribe boolean Automatically renew all subscriptions on a reconnected event true no
eventTimeout integer Time (in ms) during which a similar event is ignored 200 no
host string Kuzzle network host - yes
port integer Kuzzle network port 7512 no
offlineMode string Offline mode configuration manual no
queueTTL integer Time a queued request is kept during offline mode, in milliseconds 120000 no
queueMaxSize integer Number of maximum requests kept during offline mode 500 no
replayInterval integer Delay between each replayed requests, in milliseconds 10 no
reconnectionDelay integer number of milliseconds between reconnection attempts 1000 no
sslConnection boolean Switch Kuzzle connection to SSL mode false no
volatile object Common volatile data, will be sent to all future requests - no

Properties

Property name Type Description Writable?
autoQueue boolean Automatically queue all requests during offline mode Yes
autoReconnect boolean Automatically reconnect after a connection loss No
autoReplay boolean Automatically replay queued requests on a reconnected event Yes
autoResubscribe boolean Automatically renew all subscriptions on a reconnected event Yes
host string Target Kuzzle host No
port integer Target Kuzzle port No
jwt string Token used in requests for authentication. Yes
offlineQueue object Contains the queued requests during offline mode No
offlineQueueLoader function Called before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queue Yes
queueFilter function Called during offline mode. Takes a request object as arguments and returns a boolean, indicating if a request can be queued Yes
queueMaxSize integer Number of maximum requests kept during offline mode Yes
queueTTL integer Time a queued request is kept during offline mode, in milliseconds Yes
replayInterval integer Delay between each replayed requests Yes
reconnectionDelay integer Number of milliseconds between reconnection attempts No
sslConnection boolean Connect to Kuzzle using SSL No
volatile object Common volatile data, will be sent to all future requests Yes

Notes:

  • multiple methods allow passing specific volatile data. These volatile data will be merged with the global Kuzzle volatile object when sending the request, with the request specific volatile taking priority over the global ones.
  • the queueFilter property is a function taking an object as an argument. This object is the request sent to Kuzzle, following the Kuzzle API format
  • if queueTTL is set to 0, requests are kept indefinitely
  • The offline buffer acts like a first-in first-out (FIFO) queue, meaning that if the queueMaxSize limit is reached, older requests are discarded to make room for new requests
  • if queueMaxSize is set to 0, an unlimited number of requests is kept until the buffer is flushed
  • the offlineQueueLoader must be set with a function, taking no argument, and returning an array of objects containing a query member with a Kuzzle query to be replayed, and an optional cb member with the corresponding callback to invoke with the query result
  • updates to autoReconnect, reconnectionDelay and sslConnection properties will only take effect on next connect call

Return

The Kuzzle instance.

Usage

kuzzleio::options options = KUZZLE_OPTIONS_DEFAULT;
options.auto_resubscribe = false;

kuzzleio::Kuzzle *kuzzle = new kuzzleio::Kuzzle("kuzzle", &options);

copts := types.NewOptions()
copts.SetPort(7512)
copts.SetAutoResubscribe(false)
conn := websocket.NewWebSocket("kuzzle", copts)

k, _ := kuzzle.NewKuzzle(conn, nil)

Options options = new Options();
options.setAutoResubscribe(false);

Kuzzle kuzzle = new Kuzzle("kuzzle", options);

const options = {
  host: 'localhost',
  autoResubscribe: false
};

// Instantiate the SDK with an embedded protocol
const kuzzleWS = new Kuzzle('websocket', options);

// Instantiate the SDK with a custom protocol
const customProtocol = new MyCustomProtocol();
const kuzzleCustom = new Kuzzle(customProtocol, options);