Kotest offers an extension that spins up an embedded Kafka instance. This can help in situations where using the kafka docker images are an issue.
To use this extension add the
io.kotest.extensions:kotest-extensions-embedded-kafka module to your test compile path.
embeddedKafkaListener listener in your test class:
And the broker will be started once the spec is created and stopped once the spec completes.
Note: The underlying embedded kafka library uses a global object for state. Do not start multiple kafka instances at the same time.
To create a consumer and producer we can use methods on the listener
You can create a new instance of the listener specifying a port and then use that instance rather than the default instance.