Create export options based on event stream content
This function requires Streaming Data Framework for MATLAB® Production Server™.
detects export options from an event stream and returns them in
opts = detectExportOptions(
These options specify the rules for transforming MATLAB variables into streaming data. To determine which streaming data type best
matches the type of each column variable,
a row of timetable data and includes the type information in
To get and set the types of the variables as they are exported from MATLAB to the stream, use
To export data from MATLAB to a stream, use
Detect Data Export Options from Event Stream
Assume that you have a Kafka® server running at the network address
that has a topic
KafkaStream object connected to the
inKS = kafkaStream("kafka.host.com",9092,"Triangles");
Read events from the
Triangles topic into a timetable. Preview the
data by viewing the first row. The
c triangle side lengths are stored as strings.
tt = readtimetable(inKS); row = tt(1,:)
row = 1×3 timetable timestamp a b c ___________ ____ ____ ____ 03-Sep-2022 "15" "31" "36"
detectExportOptions to generate an
ExportOptions object from the Kafka stream object. The function obtains the types used to export the variables
from the first row of the timetable.
opts = detectExportOptions(inKS,row);
getvartype to confirm that the side length variables are
currently exported to the stream as strings.
type = getvartype(opts,["a" "b" "c"]);
type = 1×3 string array "string" "string" "string"
Update the export options so that the side lengths are exported as
double values. Confirm the updated options by using
opts = setvartype(opts,["a","b","c"],"double"); [name,type] = getvartype(opts); fprintf("%s: %s\n", [name; type])
a: double b: double c: double
Connect to the stream to export data to
outKS = kafkaStream("kafka.host.com",9092,"numericTriangles", ... ExportOptions=opts)
outKS = KafkaStream with properties: Topic: "numericTriangles" Group: "85c42e39-695d-467a-86f0-f0095792e7de" Order: EventTime Host: "kafka.host.com" Port: 9092 ConnectionTimeout: 30 RequestTimeout: 61 ImportOptions: "None" ExportOptions: "Source: string" PublishSchema: "true" WindowSize: 50 KeyVariable: "key" KeyEncoding: "utf16" KeyType: "text" KeyByteOrder: "BigEndian" BodyEncoding: "utf8" BodyFormat: "JSON" ReadLimit: "Size" TimestampResolution: "Milliseconds"
Export the timetable to the new stream. The triangle side lengths in this stream are
stream — Object connected to event stream
KafkaStream object |
Object connected to an event stream, specified as a
row — Row of MATLAB timetable data
Row of MATLAB timetable data.
row must be an example of the data
that you intend to write to the stream.
the columns of this row to set the variable names and types in the export
tt(1,:) extracts the first row of data from timetable
format — Format of output stream
"Event" (default) |
Format of the output stream, specified as one of these options:
"Event"— Native, default even stream format
"InfluxDB"— Format specifically used by InfluxDB
opts — Event stream export options
Event stream export options, returned as an
Introduced in R2022b