Main Content

seek

Set position in event stream to begin processing events

Since R2022b

    This function requires Streaming Data Framework for MATLAB® Production Server™.

    Description

    seek(esp,position) sets the stream position at which to begin processing the event stream with processor esp.

    example

    seek(esp,position,Name=Value) additionally specifies options to manage data caching.

    Examples

    collapse all

    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

    collapse all

    Object to process event streams, specified as an EventStreamProcessor object.

    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.

    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

    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