Reading from Sockets
Configured for a socket, the ECD Adapter and Agent (ECDA) reads or writes data streamed from a client program using TCP or UDP. The adapter listens or inserts at a configurable port awaiting client connections. Incoming packets are streamed as described below.
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.
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 a socket, you need to create a server object which references the ECDA data wrapper of type 'NET', as well as connection information for the socket, such as format type, port, character encoding, whether or not to write a header, and the host name. You could also configure this information as part of a stream definition, but it is best practice to define it as part of a server, since you can reuse the server object with multiple streams.
CREATE OR REPLACE SERVER "NetWriterServer" TYPE 'NET'
FOREIGN DATA WRAPPER ECDA
write_header 'FALSE', );
Note: ECD Adapter server definitions need to reference the ECD foreign data wrapper. You can do so with the syntax FOREIGN DATA WRAPPER ECDA.
Next, you create a foreign stream object. Streams, like most SQL objects (but unlike data wrappers and servers), should be created within 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 "NetReaderStream."
CREATE OR REPLACE FOREIGN STREAM "NetReaderStream"
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.
# Port, format, host
# Schema, name, and parameter signature of origin stream
ROWTYPE=RECORDTYPE(VARCHAR(2040) id, VARCHAR(2040) reported_at, VARCHAR(2040) shift_no, VARCHAR(2040) trip_no, VARCHAR(2040) route_variant_id)
The following columns may be auto generated by the file adapter if you are doing a select, that is, reading from the file.
Input only. Remote host from which this row was read.
Input only. Remote port from which this row was read.