I’ve got an unconventional setup requiring me to use a Kafka testcontainer that needs to be available from several contexts:
- process/ app A; another testcontainer, obviously running from within docker, whose
localhost
is different from host’s - process B; The ‘main’ process utilizing the testcontainers,
localhost
is the host’s
How I have this currently setup is by trying to use hostname that can be used to connect with both sides, and have process A set to connect to boostrap server using the hostname (creating the url myself), and B using the output from getBootstrapServers()
. Process B has no issues connecting. Process A however can connect to the Kafka instance, but the addresses given from the bootstrap server points to localhost
, which kills the connection.
Is there a way to get the kafka server to report the hostname I give it for Docker? I have tried withListener
, but this causes instability/ breaks the kafka instance, preventing it from coming up at all. Any other recommendations to get this going? I’m imaginging if I use the hostname for both connections, then that should work but it’s a moot point if Kafka just reports back with localhost
.
Setup of kafka:
RedpandaContainer kafka = new RedpandaContainer(DockerImageName.parse("docker.redpanda.com/redpandadata/redpanda:v23.1.2"))
.withNetwork(Network.SHARED)
.withAccessToHost(true)
.withNetworkAliases(KAFKA_DEVSERVICE_HOSTNAME)
.withListener(() -> KAFKA_DEVSERVICE_HOSTNAME + ":9092")
;
In another setup of Red Panda, I have the advertised listeners configured via the --advertise-kafka-addr
command argument, but can’t find any documentation indicating environment variables that would do the same, and unsure I want to override the command for the testcontainer.