Constructor

var kuzzle = new Kuzzle('localhost', {
  defaultIndex: 'some index',
  autoReconnect: true,
  headers: {someheader: "value"},
  port: 7512
});

// A callback is also available and will be invoked once connected to the Kuzzle instance:
kuzzle = new Kuzzle('localhost', function (err, res) {
  // ...
});
import io.kuzzle.sdk.core.Kuzzle;
import io.kuzzle.sdk.core.Options;

Options options = new Options();

options.setDefaultIndex("some index")
  .setAutoReconnect(true),
  .setHeaders(new JSONObject().put("someheader", "value"))
  .setPort(7512);

Kuzzle kuzzle = new Kuzzle("localhost", options, new ResponseListener<Void>() {
 @Override
 public void onSuccess(Void object) {
   // invoked once connected, object contains the kuzzle instance
 }

 @Override
 public void onError(JSONObject error) {
   // Handle connection error
 }
});
<?php
use \Kuzzle\Kuzzle;

$kuzzle = new Kuzzle('localhost', [
  'defaultIndex' => 'some index',
  'port' => 7512
]);

This is the main entry point to communicate with Kuzzle. Every other objects inherits properties from the Kuzzle object.


Kuzzle(host, [options], [callback])

ArgumentsTypeDescription
hoststringThe server name (or the IP address) of a Kuzzle instance
optionsJSON objectOptional Kuzzle connection configuration
callbackfunctionOptional callback

Options

OptionTypeDescriptionDefault
autoQueuebooleanAutomatically queue all requests during offline modefalse
autoReconnectbooleanAutomatically reconnect after a connection losstrue
autoReplaybooleanAutomatically replay queued requests on a reconnected eventfalse
autoResubscribebooleanAutomatically renew all subscriptions on a reconnected eventtrue
connectstringManually or automatically connect to the Kuzzle instanceauto
defaultIndexstringSet the default index to use
headersJSON objectCommon headers for all sent documents
volatileJSON objectCommon volatile data, will be sent to all future requests
offlineModestringOffline mode configurationmanual
portintegerKuzzle network port7512
queueTTLintegerTime a queued request is kept during offline mode, in milliseconds120000
queueMaxSizeintegerNumber of maximum requests kept during offline mode500
replayIntervalintegerDelay between each replayed requests, in milliseconds10
reconnectionDelayintegernumber of milliseconds between reconnection attempts1000
sslConnectionbooleanSwitch Kuzzle connection to SSL modefalse

Notes:

  • the offlineMode option only accepts the manual and auto values

Properties

Property nameTypeDescription
autoQueuebooleanAutomatically queue all requests during offline mode
autoReconnectbooleanAutomatically reconnect after a connection loss
autoReplaybooleanAutomatically replay queued requests on a reconnected event
autoResubscribebooleanAutomatically renew all subscriptions on a reconnected event
defaultIndexstringKuzzle's default index to use
headersJSON objectCommon headers for all sent documents.
hoststringTarget Kuzzle host name/address
jwtTokenstringToken used in requests for authentication.
volatileJSON objectCommon volatile data, will be sent to all future requests
offlineQueueJSON objectContains the queued requests during offline mode
offlineQueueLoaderfunctionCalled before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queue
portintegerKuzzle network port
queueFilterfunctionCalled during offline mode. Takes a request object as arguments and returns a boolean, indicating if a request can be queued
queueMaxSizeintegerNumber of maximum requests kept during offline mode
queueTTLintegerTime a queued request is kept during offline mode, in milliseconds
replayIntervalintegerDelay between each replayed requests
reconnectionDelayintegerNumber of milliseconds between reconnection attempts
sslConnectionbooleanConnect to Kuzzle using SSL

Notes:

  • if connect is set to manual, the connect method will have to be called manually
  • the kuzzle instance will automatically queue all requests, and play them automatically once a first connection is established, regardless of the connect or offline mode option values.
  • multiple methods allow passing specific volatile data. These volatile data will be merged with the global Kuzzle object volatile when sending the request, with the request specific volatile taking priority over the global ones.
  • the queueFilter property is a function taking a JSON 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 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 host, port, autoReconnect, reconnectionDelay and sslConnection properties will only take effect on next connect call

Callback response

If the connection succeeds, resolves to the Kuzzle object itself. If the connect option is set to manual, the callback will be called after the connect method is resolved.