In our tests we use the class-level annotation @EmbeddedKafka to register the EmbeddedKafkaBroker bean:
@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9502", "port=9502"})
We specify the port and it it properly used.
But after update from SpringBoot 3.1.6 to SpringBoot 3.2.1 our tests started failing and what we identified was that with the default implementation (EmbeddedKafkaKraftBroker) a random port and not the specified one is used.
What worked for us was to switch to the legacy implementation (EmbeddedKafkaZKBroker):
@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9502", "port=9502" }, **kraft = false**)
However we expect the default implementation to support the possibility to use specified ports.
Comment From: wilkinsona
@EmbeddedKafka is part of Spring Kafka. This issue is a duplicate of https://github.com/spring-projects/spring-kafka/issues/2936.