Main Content

preview

Preview subset of events from event stream

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

    Description

    example

    tt = preview(stream) returns a timetable containing the first eight events from an event stream without advancing the read position. Multiple calls to preview return the same set of events.

    example

    tt = preview(stream,ReadLimit="Time",RequestTimeout=rt) specifies the request timeout value rt when previewing data in an event stream. This syntax is valid only for KafkaStream objects.

    Examples

    collapse all

    Create an inMemoryStream object to read and write events to an event stream hosted by MATLAB.

    is = inMemoryStream;

    Write timetable data to the event stream.

    load indoors
    writetimetable(is,indoors)

    Preview the first 8 events in the stream.

    preview(is)
    ans =
    
      8×2 timetable
    
               Time            Humidity    AirQuality
        ___________________    ________    __________
    
        2015-11-15 00:00:24       36           80    
        2015-11-15 01:13:35       36           80    
        2015-11-15 02:26:47       37           79    
        2015-11-15 03:39:59       37           82    
        2015-11-15 04:53:11       36           80    
        2015-11-15 06:06:23       36           80    
        2015-11-15 07:19:35       36           80    
        2015-11-15 08:32:47       37           80   

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

    Create a KafkaStream object for reading from and writing to the IndoorTemp topic.

    ks = kafkaStream("kafka.host.com",9092,"IndoorTemp");

    Write timetable data to the event stream.

    load indoors
    writetimetable(ks,indoors)

    Set a timeout value of 30 seconds when previewing the first 8 events.

    preview(ks,ReadLimit="Time",RequestTimeout=30)
    ans =
    
      8×2 timetable
    
               Time            Humidity    AirQuality
        ___________________    ________    __________
    
        2015-11-15 00:00:24       36           80    
        2015-11-15 01:13:35       36           80    
        2015-11-15 02:26:47       37           79    
        2015-11-15 03:39:59       37           82    
        2015-11-15 04:53:11       36           80    
        2015-11-15 06:06:23       36           80    
        2015-11-15 07:19:35       36           80    
        2015-11-15 08:32:47       37           80   

    Input Arguments

    collapse all

    Object connected to an event stream, specified as a KafkaStream, InMemoryStream, or TestStream object.

    Number of seconds to wait before terminating a request that has not yet begun to transfer data, specified as a positive integer.

    If the stream provider is Kafka, the wait time includes connecting to the Kafka host as well as data transfer between the Kafka host and the client.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Version History

    Introduced in R2022b