Skip to content

Commit a3fd554

Browse files
authored
feat: exposing necessary Kafka consts in both Apache and Confluent Kafka (#409)
Exposing defaults (cluster id, broker id, and replication factor) in both Apache and Confluent Kafka.
1 parent 60331dc commit a3fd554

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/kafka/apache.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ const TAG: &str = "3.8.0";
1616
pub const KAFKA_PORT: ContainerPort = ContainerPort::Tcp(9092);
1717

1818
const START_SCRIPT: &str = "/opt/kafka/testcontainers_start.sh";
19-
const DEFAULT_INTERNAL_TOPIC_RF: usize = 1;
20-
const DEFAULT_CLUSTER_ID: &str = "5L6g3nShT-eMCtK--X86sw";
21-
const DEFAULT_BROKER_ID: usize = 1;
19+
20+
/// The default Replication Factor to use.
21+
pub const DEFAULT_INTERNAL_TOPIC_RF: usize = 1;
22+
23+
/// The default cluster id to use.
24+
pub const DEFAULT_CLUSTER_ID: &str = "5L6g3nShT-eMCtK--X86sw";
25+
26+
/// The default broker id.
27+
pub const DEFAULT_BROKER_ID: usize = 1;
2228

2329
/// Module to work with [`Apache Kafka`] broker
2430
///

src/kafka/confluent.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ pub const KAFKA_PORT: ContainerPort = ContainerPort::Tcp(9093);
1818
/// [`Zookeeper`]: https://zookeeper.apache.org/
1919
pub const ZOOKEEPER_PORT: ContainerPort = ContainerPort::Tcp(2181);
2020

21+
/// The default Replication Factor to use.
22+
pub const DEFAULT_INTERNAL_TOPIC_RF: usize = 1;
23+
24+
/// The default cluster id to use.
25+
pub const DEFAULT_CLUSTER_ID: &str = "5L6g3nShT-eMCtK--X86sw";
26+
27+
/// The default broker id.
28+
pub const DEFAULT_BROKER_ID: usize = 1;
29+
2130
/// Module to work with [`Apache Kafka`] inside of tests.
2231
///
2332
/// Starts an instance of Kafka based on the official [`Confluent Kafka docker image`].
@@ -80,11 +89,12 @@ impl Default for Kafka {
8089
port = KAFKA_PORT.as_u16(),
8190
),
8291
);
83-
env_vars.insert("KAFKA_BROKER_ID".to_owned(), "1".to_owned());
92+
env_vars.insert("KAFKA_BROKER_ID".to_owned(), DEFAULT_BROKER_ID.to_string());
8493
env_vars.insert(
8594
"KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR".to_owned(),
86-
"1".to_owned(),
95+
DEFAULT_INTERNAL_TOPIC_RF.to_string(),
8796
);
97+
env_vars.insert("CLUSTER_ID".to_owned(), DEFAULT_CLUSTER_ID.to_owned());
8898

8999
Self { env_vars }
90100
}

0 commit comments

Comments
 (0)