readevents
This function requires Streaming Data Framework for MATLAB® Production Server™.
Syntax
Description
Examples
Read Raw Events From Kafka
Assume that you have a Kafka server running at the network address kafka.host.com:9092
that has a topic RecamanSequence
.
Create a KafkaStream
object for reading from and writing to the
RecamanSequence
topic.
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
RecamanSequence
topic.
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 kafkaStream
. To
change the timeout duration, for example, to 15 seconds, specify
RequestTimeout=15
in the call to the KafkaStream
object, ks
.
Input Arguments
ks
— Object connected to Kafka stream topic
KafkaStream
object
Object connected to a Kafka stream topic, specified as a KafkaStream
object.
Output Arguments
event
— Event information
structure array
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.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| char
| string
value
— Event value
byte array
Event value, specified as a byte array with a format and encoding determined by the BodyFormat
and 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.
Data Types: string
| uint8
| uint16
timestamp
— Event timestamp or ingest timestamp
datetime scalar
Timestamp of event occurrence or timestamp of event ingestion in Kafka, specified as a datetime scalar.
Data Types: datetime
Version History
Introduced in R2022b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)