Click to copy
Working With Topics • Reviewed for ksqlDB 0.29
How to Create Topic in ksqlDB
In ksqlDB, you create a topic by creating a stream where the topic set as KAFKA_TOPIC
doesn't exist yet. Here is an example:
CREATE STREAM flights (
flight_id STRING
) WITH (
KAFKA_TOPIC = 'flights_topic',
PARTITIONS = 10,
REPLICAS = 3
);
You can set the number of partitions and the replication factor inside the WITH
clause using the PARTITIONS
and REPLICAS
stream properties respectively. If not set, the default values set at the Apache Kafka brokers will be used.
If you are only interested in creating the topic, you can drop the stream by running:
DROP STREAM flights;
without the modifier DELETE TOPIC
.
Was this article helpful?