Function mz_kafka_util::admin::create_new_topic

source ·
pub async fn create_new_topic<'a, C>(
    client: &'a AdminClient<C>,
    admin_opts: &AdminOptions,
    new_topic: &'a NewTopic<'a>,
) -> Result<bool, CreateTopicError>
where C: ClientContext,
Expand description

Creates a Kafka topic and waits for it to be reported in the broker metadata.

This function is a wrapper around AdminClient::create_topics that attempts to ensure the topic creation has propagated throughout the Kafka cluster before returning. Kafka topic creation is asynchronous, so attempting to consume from or produce to a topic immediately after its creation can result in “unknown topic” errors.

This function does not return successfully unless it can find the metadata for the newly-created topic in a call to rdkafka::client::Client::fetch_metadata and verify that the metadata reports the topic has the number of partitions requested in new_topic. Empirically, this seems to be the condition that guarantees that future attempts to consume from or produce to the topic will succeed.

Returns a boolean indicating whether the topic already existed.