Constructor #
This is the main entry point to communicate with Kuzzle. Every other object inherits properties from the Kuzzle
object.
Kuzzle(host, [options], [callback]) #
Arguments | Type | Description |
---|---|---|
host | string | The server name (or the IP address) of a Kuzzle server installation |
options | JSON object | Optional Kuzzle connection configuration |
callback | function | Optional callback |
Options #
Option | Type | Description | Default |
---|---|---|---|
autoQueue | boolean | Automatically queue all requests during offline mode | false |
autoReconnect | boolean | Automatically reconnect after a connection loss | true |
autoReplay | boolean | Automatically replay queued requests on a reconnected event | false |
autoResubscribe | boolean | Automatically renew all subscriptions on a reconnected event | true |
connect | string | Manually or automatically connect to the Kuzzle instance | auto |
defaultIndex | string | Set the default index to use | |
headers | JSON object | Common headers for all sent documents | |
volatile | JSON object | Common volatile data, will be sent to all future requests | |
offlineMode | string | Offline mode configuration | manual |
port | integer | Kuzzle network port | 7512 |
queueTTL | integer | Time a queued request is kept during offline mode, in milliseconds | 120000 |
queueMaxSize | integer | Number of maximum requests kept during offline mode | 500 |
replayInterval | integer | Delay between each replayed requests, in milliseconds | 10 |
reconnectionDelay | integer | number of milliseconds between reconnection attempts | 1000 |
ssl | boolean | Switch Kuzzle connection to SSL mode | false |
Notes:
- the
offlineMode
option only accepts themanual
andauto
values
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 | No |
defaultIndex | string | Kuzzle's default index to use | Yes |
headers | JSON object | Common headers for all sent documents. | Yes |
host | string | Target Kuzzle host name/address | No |
jwtToken | string | Token used in requests for authentication. | Yes |
offlineQueue | JSON 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 |
port | integer | Kuzzle network port | No |
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 |
ssl | boolean | Connect to Kuzzle using SSL | No |
volatile | JSON object | Common volatile data, will be sent to all future requests | Yes |
Notes:
- if
connect
is set tomanual
, theconnect
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. Thesevolatile
data will be merged with the global Kuzzlevolatile
object when sending the request, with the request specificvolatile
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 to0
, 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 to0
, 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 aquery
member with a Kuzzle query to be replayed, and an optionalcb
member with the corresponding callback to invoke with the query result - updates to
host
,port
,autoReconnect
,reconnectionDelay
andsslConnection
properties will only take effect on nextconnect
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.
Usage #
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
}
});
Edit this page on Github(opens new window)