Skip to main content

Getting Started with Event Delivery Client SDK

PhotonIQ offers SDK to enable you connect to and deliver event streams to your applications, services, and several other data-volatile use cases. It supports both WebSocket and Server-Sent Events (SSE) connections.

Quick Start

This section demonstrates some simple tasks to help get you started using this client SDK in two ways.

This quickstart guide will guide you through:

  • Connecting to an event delivery service
  • Querying and subscribing that service and receiving query results and updates
<script src="path/to/photoniq-eds-sdk.min.js"></script>
  • Basic Example:

Connect to Event Delivery Service, retrieve and subsribe to SQL:

let config = {
host: "<YOUR-PHOTONIQ>.photoniq.macrometa.io",
customerId: "<YOUR-CUSTOMER-ID>",
apiKey: "<YOUR-API-KEY>",
fabric: "<YOUR-FABRIC>",
};

let connection = PhotoniqEdsSdk.connect(config);

let querySet = connection.querySet();

querySet.retrieveAndSubscribe("SELECT * FROM <YOUR-COLLECTION> WHERE key=<YOUR-KEY>", (event) => {
console.log(`Message event: `, event);
})
note

The example uses a WebSocket connection. To switch to an SSE connection, add connectionTypes: ["sse"] to the config. For a priority connection that falls back to WebSocket in case of network issues, use connectionTypes: ["sse", "ws"].

Supported Methods

Connect

Create a new Connection instance and establish connection to PhotonIQ EDS server:

let connection: Connection = PhotoniqEdsSdk.connect(config);

Create

Create a new Connection instance:

let connection = PhotoniqEdsSdk.create(config);

Config instance schema:

PropertyTypeRequredDescription
hoststringYesHost of the connection
customerIdstringYesCustomer ID credentails
apiKeystringYesApiKey credentails
fabricstringNoFabric to be used. Default is _system
connectionTypes(string | SubConfig)[]NoUse type of connection and priority. Default is ["ws"]. Types: ws, sse
autoReconnectbooleanNoAutomatically reconnect in case of network issues. Default is true

SubConfig instance schema:

PropertyTypeRequredDescription
typestringYesType of the connection. Value: ws or sse
customerIdstringNoCustomer ID credentails. Default set from Config
apiKeystringNoApiKey credentails. Default set from Config
fabricstringNoFabric to be used. Default set from Config
pingSecondsnumberNoSeconds between ping-pong messages to the WebSocket server. Default is 29. Acceptable only for ws connection.
flushTimeoutMsnumberNoSeconds between ping-pong messages to the WebSocket server. Default is 20. Acceptable only for sse connection.