Main Content


Create topic in Kafka cluster

Since R2022b

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



    createTopic(ks) creates a topic on the Kafka® host, if Kafka cluster permissions allow creation. The KafkaStream object ks specifies the topic to create and the network address of the Kafka host that contains the topic.

    createTopic(ks,MissingTopic=action) specifies whether to create a topic Kafka or fail when the topic is missing. If the Kafka cluster that you are writing to is configured to auto-create topics, specifying action has no effect.


    collapse all

    Assume that you have a Kafka server running at network address

    Create an object connected to the Kafka host that interacts with a topic called CoolingFan.

    ks = kafkaStream("",9092,"CoolingFan");

    If the CoolingFan topic does not exist during object creation, you can create it. You must have the necessary permissions to create topics.


    Input Arguments

    collapse all

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

    Action to take if the topic does not exist, specified as one of the following values:

    • create — Creates new topic, if you have the required permissions on the Kafka host.

    • fail — Does not create a new topic.

    Data Types: char | string

    Version History

    Introduced in R2022b