Main Content

flush

Reset read window boundaries

Since R2022b

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

    Syntax

    Description

    flush(ks) resets the read window boundaries to enable reading of incomplete windows of data from the Kafka® stream ks.

    example

    Examples

    collapse all

    Assume that you have a Kafka server running at the network address kafka.host.com:9092 that has a topic CoolingFan.

    Also assume that the CoolingFan topic has 5120 messages.

    Create a KafkaStream object to connect to the Kafka host. Configure the object to read 500 messages, or events, at a time.

    inKS = kafkaStream("kafka.host.com",9092,"CoolingFan",Rows=500);
    

    Configure a second KafkaStream object to connect to the CoolingFanOut topic. The Kafka host writes messages to this topic.

    outKS = kafkaStream("kafka.host.com",9092,"CoolingFanOut",Rows=500);

    Read 10 windows of message data from CoolingFan and write the data to CoolingFanOut. This operation processes the first 5000 messages from CoolingFan.

    for idx = 1:10
        tt = readtimetable(inKS);
        writetimetable(outKS,tt)
    end

    Read one more window of messages from CoolingFan. This topic has only 120 messages left to be read. Because readtimetable does not receive a full window of 500 messages, it times out and does not read the remaining messages.

    tt = readtimetable(inKS)
    
    tt =
    
      0×0 empty timetable

    To enable reading the 120 remaining messages, flush the stream.

    flush(inKS)

    Read the remaining messages into a timetable and write them to CoolingFanOut. Though the number of messages is smaller than the window size, readtimetable is able to read the remaining messages.

    tt = readtimetable(inKS);
    writetimetable(outKS,tt)

    Input Arguments

    collapse all

    Object connected to a Kafka stream topic, specified as a KafkaStream object.

    Version History

    Introduced in R2022b