Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Fede1024 Rust rdkafka MockCluster Create Topic

From Leeroopedia


Knowledge Sources
Domains Testing, Messaging
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete mock topic creation method provided by rust-rdkafka's MockCluster.

Description

MockCluster::create_topic creates a topic on the mock cluster via rd_kafka_mock_topic_create FFI call. It takes the topic name, partition count, and replication factor. Returns a KafkaError::MockCluster on failure.

Usage

Call after MockCluster::new() to create topics before producing or consuming.

Code Reference

Source Location

  • Repository: rust-rdkafka
  • File: src/mocking.rs
  • Lines: L184-201

Signature

impl<'c, C: ClientContext> MockCluster<'c, C> {
    pub fn create_topic(
        &self,
        topic: &str,
        partition_count: i32,
        replication_factor: i32,
    ) -> KafkaResult<()>;
}

Import

use rdkafka::mocking::MockCluster;

I/O Contract

Inputs

Name Type Required Description
topic &str Yes Topic name to create
partition_count i32 Yes Number of partitions
replication_factor i32 Yes Replication factor

Outputs

Name Type Description
returns KafkaResult<()> Success or MockCluster error

Usage Examples

mock_cluster
    .create_topic("test-topic", 3, 1)
    .expect("Failed to create topic");

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment