Main Content

createTopic

Create topic in Kafka cluster

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

    Description

    example

    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.

    Examples

    collapse all

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

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

    ks = kafkaStream("kafka.host.com",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.

    createTopic(ks)

    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