SDK
SDK Golang v2.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

Constructor #

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

This interface implements the KuzzleEventEmitter interface

Arguments #

NewKuzzle(protocol protocol.Protocol) (*Kuzzle, error)
ArgumentTypeDescription
protocol
protocol.Protocol
The protocol used by the SDK instance

protocol #

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

  • websocket.Websocket

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

ArgumentTypeDescriptionRequired
host
string
Kuzzle hostname to connect toyes
options
types.Options
Kuzzle connection configurationyes

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

OptionTypeDescriptionDefaultRequired
autoQueue
bool
Automatically queue all requests during offline modefalseno
autoReconnect
bool
Automatically reconnect after a connection losstrueno
autoReplay
bool
Automatically replay queued requests on a reconnected eventfalseno
autoResubscribe
bool
Automatically renew all subscriptions on a reconnected eventtrueno
offlineMode
int
Offline mode configuration. types.Manual or types.Autotypes.Manualno
port
int
Target Kuzzle port7512no
queueTTL
int
Time a queued request is kept during offline mode, in milliseconds120000no
queueMaxSize
int
Number of maximum requests kept during offline mode500no
replayInterval
Duration
Delay between each replayed requests, in milliseconds10no
reconnectionDelay
Duration
number of milliseconds between reconnection attempts1000no
sslConnection
bool
Switch Kuzzle connection to SSL modefalseno
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 nameTypeDescriptionAvailability
autoQueue
bool
Automatically queue all requests during offline modeGet/Set
autoReconnect
bool
Automatically reconnect after a connection lossGet
autoReplay
bool
Automatically replay queued requests on a reconnected eventGet/Set
autoResubscribe
bool
Automatically renew all subscriptions on a reconnected eventGet/Set
host
string
Target Kuzzle hostGet
port
int
Target Kuzzle portGet
jwt
string
Token used in requests for authentication.Get/Set
offlineQueue
QueryObject
Contains the queued requests during offline modeGet
offlineQueueLoader
OfflineQueueLoader
Called before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queueGet/Set
queueFilter
QueueFilter
Called during offline mode. Takes a request object as arguments and returns a bool, indicating if a request can be queuedGet/Set
queueMaxSize
int
Number of maximum requests kept during offline modeGet/Set
queueTTL
Duration
Time a queued request is kept during offline mode, in millisecondsGet/Set
replayInterval
Duration
Delay between each replayed requestsGet/Set
reconnectionDelay
Duration
Number of milliseconds between reconnection attemptsGet
sslConnection
bool
Connect to Kuzzle using SSLGet
volatile
VolatileData
Common volatile data, will be sent to all future requestsGet/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.

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