Skip to content

Commit

Permalink
refactor!: changed KAFKA_PORT to a ContainerPort (#185)
Browse files Browse the repository at this point in the history
refactor!: made sure that `KAFKA_PORT` follow the convention of being a
`ContainerPort`

This reverts commit
1c6ba59.

It is based on
#183
=> if said PR is merged, the unrelated changes (included to make
merge-conflicts less likely) will merge/rebase away and only the kafka
changes are left.

---------

Co-authored-by: Artem Medvedev <i@ddtkey.com>
  • Loading branch information
CommanderStorm and DDtKey committed Aug 22, 2024
1 parent 377f162 commit 2facbec
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/kafka/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TAG: &str = "6.1.1";
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Kafka`]: https://kafka.apache.org/
pub const KAFKA_PORT: u16 = 9093;
pub const KAFKA_PORT: ContainerPort = ContainerPort::Tcp(9093);
/// Port that the [`Zookeeper`] part of the container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
Expand All @@ -33,7 +33,10 @@ impl Default for Kafka {
);
env_vars.insert(
"KAFKA_LISTENERS".to_owned(),
format!("PLAINTEXT://0.0.0.0:{KAFKA_PORT},BROKER://0.0.0.0:9092"),
format!(
"PLAINTEXT://0.0.0.0:{port},BROKER://0.0.0.0:9092",
port = KAFKA_PORT.as_u16(),
),
);
env_vars.insert(
"KAFKA_LISTENER_SECURITY_PROTOCOL_MAP".to_owned(),
Expand All @@ -45,7 +48,10 @@ impl Default for Kafka {
);
env_vars.insert(
"KAFKA_ADVERTISED_LISTENERS".to_owned(),
format!("PLAINTEXT://localhost:{KAFKA_PORT},BROKER://localhost:9092",),
format!(
"PLAINTEXT://localhost:{port},BROKER://localhost:9092",
port = KAFKA_PORT.as_u16(),
),
);
env_vars.insert("KAFKA_BROKER_ID".to_owned(), "1".to_owned());
env_vars.insert(
Expand Down Expand Up @@ -95,7 +101,7 @@ zookeeper-server-start zookeeper.properties &
}

fn expose_ports(&self) -> &[ContainerPort] {
&[ContainerPort::Tcp(KAFKA_PORT)]
&[KAFKA_PORT]
}

fn exec_after_start(
Expand All @@ -115,7 +121,7 @@ zookeeper-server-start zookeeper.properties &
"--add-config".to_string(),
format!(
"advertised.listeners=[PLAINTEXT://127.0.0.1:{},BROKER://localhost:9092]",
cs.host_port_ipv4(ContainerPort::Tcp(KAFKA_PORT))?
cs.host_port_ipv4(KAFKA_PORT)?
),
];
let ready_conditions = vec![WaitFor::message_on_stdout(
Expand Down

0 comments on commit 2facbec

Please sign in to comment.