KEMBAR78
Fix Kafka listeners and advertised listeners config to come out of sync by ThomasKasene · Pull Request #11068 · testcontainers/testcontainers-java · GitHub
Skip to content

Conversation

@ThomasKasene
Copy link
Contributor

KafkaContainer and ConfluentKafkaContainer both have a pair of HashSet properties: listeners and advertisedListeners. At some point, these are being fed into KafkaHelper.resolveListeners(GenericContainer<?>, Set<String>) and KafkaHelper.resolveAdvertisedListeners(Set<Supplier<String>>) to help generate values for KAFKA_LISTENERS and KAFKA_ADVERTISED_LISTENERS, respectively. Each registered listener will get assigned the protocol TC-<X> where <X> essentially is the index position of the listener in each HashSet, but since HashSet doesn't guarantee any such order, a listener might be registered as TC-0 in the KAFKA_LISTENERS env variable and as TC-1 in KAFKA_ADVERTISED_LISTENERS.

The least intrusive solution I could think of was to replace HashSet with LinkedHashSet, which does guarantee insertion order, and should therefore work better with the way the KafkaHelper methods are designed.

@ThomasKasene ThomasKasene requested a review from a team as a code owner October 2, 2025 08:10
@eddumelendez eddumelendez added this to the next milestone Oct 13, 2025
@eddumelendez eddumelendez changed the title Fixed bug that allowed configs for Kafka listeners and advertised listeners to come out of sync Fix Kafka listeners and advertised listeners config to come out of sync Oct 14, 2025
@eddumelendez eddumelendez merged commit 11881bf into testcontainers:main Oct 14, 2025
184 of 187 checks passed
@eddumelendez
Copy link
Member

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants