Reading over Web Sockets

<< Click to Display Table of Contents >>

Navigation:  Integrating SQLstream Blaze with Other Systems > Reading Data into s-Server > Reading from Other Sources  >

Reading over Web Sockets

Previous pageReturn to chapter overviewNext page

You can read data over Web Sockets using the Extensible Common Data Adapter (ECDA) or ECD Agent. This feature is new in s-Server 5.2.

All adapter or agent implementations involve configuring options. For adapters, you configure and launch the adapter in SQL, using either server or foreign stream/table options. For agents, you configure such options using a properties file and launch the agent at the command line. Many of the options for the ECD adapter and agent are common to all I/O systems. The CREATE FOREIGN STREAM topic in the Streaming SQL Reference Guide has a complete list of options for the ECD adapter.

To read from the file system, you need to create a server object which references the data wrapper ECDA and is of type 'HTTP'.

CREATE OR REPLACE SERVER "WebSocketReaderServer" TYPE 'websocket'

FOREIGN DATA WRAPPER ECDA;

 

 

Note: ECD Adapter server definitions need to reference the ECD foreign data wrapper. You can do so with the syntax FOREIGN DATA WRAPPER ECDA.

Unlike server objects, all foreign streams need to be created in a schema. The following code first creates a schema in which to run the rest of the sample code below, then creates a foreign stream named "WebSocketStream."

CREATE OR REPLACE SCHEMA "WebSocketSource";

SET SCHEMA '"WebSocketSource"';

 

CREATE FOREIGN STREAM "WebSocketStream"

("recNo" INTEGER,

"ts" TIMESTAMP,

"accountNumber" INTEGER,

"loginSuccessful" BOOLEAN,

"sourceIP" VARCHAR(32),

"destIP" VARCHAR(32),

"customerId" INTEGER)

SERVER "WebSocketReaderServer"

OPTIONS (

       PARSER 'CSV',

       --This needs to be a web socket accessible from s-Server

       "URL" 'wss://listener-streamer-services-poc.labs.myserver.com/84be767d-bc36-4d24-82c2-fa6c88e00c1b',

       "HEADER_Connection" 'Upgrade',

       "HEADER_Authorization" 'token d90621ca-9601-4a49-96f3-160f61082c34',

       "HEADER_Upgrade" 'websocket',

       "HEADER_Host" 'listener-myserver.com',

       "HEADER_Origin" 'listener-myserver.com'

   );

 

Using the ECD Agent to Read from a Web Socket

The ECD agent takes similar options, but these options need to be formatted in a properties file along the lines of the following. These properties correspond to those defined for the adapter above.

PARSER=CSV

URL=wss://listener-streamer-services-poc.labs.myserver.com/84be767d-bc36-4d24-82c2-fa6c88e00c1b

HEADER_Connection=Upgrade

HEADER_Authorization=token d90621ca-9601-4a49-96f3-160f61082c34',

HEADER_Upgrade=websocket

HEADER_Host=listener-myserver.com

HEADER_Origin=listener-myserver.com

SCHEMA_NAME=MY_SCHEMA

TABLE_NAME=WEBSOCKETREADER_STREAM

ROWTYPE=RECORDTYPE(VARCHAR(2040) id, VARCHAR(2040) reported_at, VARCHAR(2040) shift_no, VARCHAR(2040) trip_no, VARCHAR(2040) route_variant_id)

 

Input Format

The code sample above uses CSV as a format. To use other file options, see the File Formats for Reading topic in this guide.