Read raw events from Kafka stream without schema processing applied
This function requires Streaming Data Framework for MATLAB® Production Server™.
Read Raw Events From Kafka
Assume that you have a Kafka server running at the network address
that has a topic
KafkaStream object for reading from and writing to the
ks = kafkaStream("kafka.host.com",9092,"RecamanSequence")
ks = KafkaStream with properties: Topic: "RecamanSequence" Group: "d89f5726-6abf-461d-a14e-4d40ab84c676" Order: EventTime Host: "kafka.host.com" Port: 9092 ConnectionTimeout: 30 RequestTimeout: 61 ImportOptions: "None" ExportOptions: "Source: function eventSchema" PublishSchema: "true" WindowSize: 50 KeyVariable: "key" KeyEncoding: "utf16" KeyType: "text" KeyByteOrder: "BigEndian" BodyEncoding: "utf8" BodyFormat: "JSON" ReadLimit: "Size" TimestampResolution: "Milliseconds"
Read 50 events, which is the default number of events, from the
events = readevents(ks)
events = 50×1 struct array with fields: key value timestamp
readevents blocks other operations until it reads 50 messages or
times out after 61 seconds of receiving no messages. To strictly limit blocking time to
61 seconds even if more are messages available, specify
ReadLimit=Time in the call to
change the timeout duration, for example, to 15 seconds, specify
RequestTimeout=15 in the call to the
event — Event information
Event information, returned as a structure array. Each structure in the array has these fields.
key — Event key
string array | positive integer
Event key as stored in Kafka, returned as a string array or integer. The key identifies the event source.
value — Event value
Event value, specified as a byte array with a format and encoding determined by the
BodyEncoding properties of the stream object. The event value does not undergo schema processing and appears exactly as is stored in Kafka, for example, as a JSON string.
timestamp — Event timestamp or ingest timestamp
Timestamp of event occurrence or timestamp of event ingestion in Kafka, specified as a datetime scalar.
Introduced in R2022b