Class DeepstreamClient

The main entry point for a DeepstreamClient. Clients can be created directly using the constructor or via DeepstreamFactory.getClient(), DeepstreamFactory.getClient(url) or DeepstreamFactory.getClient(url, options) to create a client and keep it as a singleton for future references.

Fields

record

Allows access to concepts related to deepstream’s realtime datastore, such as:

event

The entry point for events, such as:

rpc

The entry point for RPCs, deepstream’s request-response mechanism:

Constructors

DeepstreamClient(String url) throws URISyntaxException

Argument Type Description
options url The url to connect to

Creates a client instance using the default properties and initialises the connection to deepstream. The connection will be kept in a quarantine state and won’t be fully usable until DeepstreamClient.login() is called.

DeepstreamClient client = new DeepstreamClient("ws://localhost:6020");

DeepstreamClient(String url, Properties options) throws URISyntaxException,

Argument Type Description
options url The url to connect to
properties Properties The properties to configure the client with

Creates a client instance, merging the default options with the passed in configuration and initialises the connection to deepstream. The connection will be kept in a quarantine state and won’t be fully usable until DeepstreamClient.login() is called.

Properties options = new Properties();
properties.setProperty(ConfigOptions.RPC_RESPONSE_TIMEOUT.toString(), "10");
DeepstreamClient client = new DeepstreamClient("ws://localhost:6020", options);

Methods

void setRuntimeErrorHandler(DeepstreamRuntimeErrorHandler handler)

Argument Type Description
handler DeepstreamRuntimeErrorHandler The listener to set

Adds a DeepstreamRuntimeErrorHandler that will catch all RuntimeErrors such as AckTimeouts and allow the user to gracefully handle them.

client.setRuntimeErrorHandler(new DeepstreamRuntimeErrorHandler() {
    @Override
    public void onException(Topic topic, Event event, String errorMessage) {
        // handle error
    }
});

LoginResult login()

Authenticates the client against the platform with an empty authentication object and returns a LoginResult. To learn more about how authentication works, please have a look at the Security Overview.

DeepstreamClient client = new DeepstreamClient("ws://localhost:6020");
LoginResult result = client.login();

LoginResult login(JsonElement authParams)

Argument Type Description
authParams JsonElement JSON.serializable authentication data

Authenticates the client against the platform with the given credentials and returns a LoginResult. To learn more about how authentication works, please have a look at the Security Overview.

DeepstreamClient client = new DeepstreamClient("ws://localhost:6020");
JsonObject credentials = new JsonObject();
credentials.addProperty("email", "user@example.com");
credentials.addProperty("email", "sesame");
LoginResult result = client.login(credentials);

DeepstreamClient close()

Ends the connection to the platform.

client.addConnectionChangeListener(new ConnectionStateListener() {
    @Override
    public void connectionStateChanged(ConnectionState connectionState) {
        // will be CLOSED once the connection is successfully closed
    }
});

client.close();

DeepstreamClient addConnectionChangeListener (ConnectionStateListener listener)

Argument Type Description
connectionStateListener ConnectionStateListener The listener to add

Add a listener that can be notified via ConnectionStateListener.connectionStateChanged(state) whenever the ConnectionState changes. A list of possible connection states is available here

client.addConnectionChangeListener(new ConnectionStateListener() {
    @Override
    public void connectionStateChanged(ConnectionState connectionState) {
        // handle change
    }
});

DeepstreamClient removeConnectionChangeListener(ConnectionStateListener listener

Argument Type Description
connectionStateListener ConnectionStateListener The listener to remove

Removes a ConnectionStateListener added via DeepstreamClient.addConnectionChangeListener()

client.removeConnectionChangeListener(connectionStateChangedListener);

String getUid()

Returns a random id. The first block of characters is a timestamp, in order to allow databases to optimize for semi- sequentuel numberings.

client.getUid();