Websocket support for the Storage Broker

WebSocket Client for communicating with the Storage Broker API. Includes configuration options, parameter details, and example usage for developers

Websocket support for the Storage Broker

This page explains how to use the StorageWsClient to communicate with the Storage Broker API via WebSocket. It covers the configuration options available, including plugins, parameters, and examples of initializing and using the client.

In this guide you'll find:

  • An overview of the StorageWsClient and its purpose for interacting with the Storage Broker API.
  • Details about the configuration options, including tenant token, virtual environment, and service discovery agent.
  • Example code demonstrating how to initialize and use the client with default and global tokens.

WebSocket Client for Storage Broker API

The StorageWsClient class facilitates communication with the Storage Broker API. It extends the capabilities of the basic WebSocket client. For further information on base client operations and features, refer to the [WebSocket Client Documentation].
The following plugins are configured for the Storage Broker API:

  • Protocol Validation Plugin
  • Smart Reconnection Plugin
  • RPC Plugin

new StorageWsClient(tenantToken, virtualEnvopt, agentopt) creates a new StorageWsClient instance with the provided configuration.

Parameters

NameTypeAttributesDefaultDescription
tenantTokenstringRequired-Tenant API Token for communicating with tenant services. If not provided, it is automatically read from secrets.
virtualEnvstringOptional-Specifies the Virtual Environment for the broker.
agentexternal:ServiceDiscoveryAgentOptionalrequire('@pps/svc-discovery').agentService Discovery Agent used to locate an available broker instance.

Example

Default Service Discovery

const { StorageWsClient } = require('@pps/broker-client');
const client = new StorageWsClient(token, virtualEnv);
await client.open();
// Start sending RPCs :)
await client.close();

withGlobalToken(virtualEnvopt, agentopt) → Promise.<module:broker-client.StorageWsClient> creates a new StorageWsClient instance using the global tenant token configured by the secrets module.

Parameters

NameTypeAttributesDescription
virtualEnvstringOptionalVirtual environment name passed to the StorageWsClient constructor.
agentexternal:ServiceDiscoveryAgentOptionalService Discovery Agent passed to the StorageWsClient constructor.

Returns

A Promise that resolves to an instance of module:broker-client.StorageWsClient.


Did this page help you?
Priority Technology Holdings Logo