Reading over Web Sockets
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"
--This needs to be a web socket accessible from s-Server
"HEADER_Authorization" 'token d90621ca-9601-4a49-96f3-160f61082c34',
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.
ROWTYPE=RECORDTYPE(VARCHAR(2040) id, VARCHAR(2040) reported_at, VARCHAR(2040) shift_no, VARCHAR(2040) trip_no, VARCHAR(2040) route_variant_id)
The code sample above uses CSV as a format. To use other file options, see the File Formats for Reading topic in this guide.