seek
This function requires Streaming Data Framework for MATLAB® Production Server™.
Description
Examples
Process Events from Beginning of Stream
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 connected to the
RecamanSequence
topic.
ks = kafkaStream("kafka.host.com",9092,"RecamanSequence");
Assume that you have a stateful streaming analytic function
recamanSum
and a function to initialize the per-iteration state
data called initRecamanSum
. Create an
EventStreamProcessor
object that runs the
recamanSum
function and initializes the state data for the first
iteration with the initRecamanSum
function.
esp = eventStreamProcessor(ks,@recamanSum,@initRecamanSum);
esp = EventStreamProcessor with properties: StreamFunction: @recamanSum InputStream: [1×1 matlab.io.stream.event.KafkaStream] OutputStream: [1×1 matlab.io.stream.event.InMemoryStream] InitialState: @initRecamanSum GroupVariable: [0×0 string] ReadPosition: Beginning ArchiveName: "recamanSum" ResetStateOnSeek: 1
Iterate the streaming analytic function over ten event windows.
execute(esp,10);
Check the result of the recamanSum
function.
result = readtimetable(esp.OutputStream)
Input Arguments
esp
— Object to process event streams
EventStreamProcessor
object
Object to process event streams, specified as an EventStreamProcessor
object.
position
— Position in event stream
"Beginning"
| "End"
| "Current"
Position in an event stream, specified as one of the following values.
"Beginning"
— First event available in the event stream"End"
— End of the event stream, which is one event past the latest event in the stream"Current"
— Just past the current event in the stream
Example: seek(esp,"Beginning")
moves the event stream position to
the first event in the event stream.
Data Types: string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: seek(esp,"Beginning",ClearState=true)
moves the read position
to the first event in the stream and clears the persistent data state.
ClearState
— Flag to clear persistent state of data after calling seek
true | false
Flag to clear persistent state of data after calling the seek
function, specified as a logical scalar. The default value is the value of the
EventStreamProcessor
property ResetStateOnSeek
.
Data Types: logical
PersistState
— Per-iteration state value of stream processing function
any valid MATLAB data type
Per-iteration state value of the stream processing function after calling the
seek
function, specified as any valid MATLAB data type.
If the streaming analytic function is stateful, then
PersistState
must be a MATLAB value of the same type as the value returned by the state initialization
function set in esp
. If the streaming analytic function is
stateless, you cannot specify PersistState
.
Version History
Introduced in R2022b
See Also
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)