Skip to content

Commit

Permalink
feat: additional advertised listners/broker addresses for kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
ghthor committed Dec 17, 2024
1 parent 35bf0cd commit 7395ce5
Show file tree
Hide file tree
Showing 4 changed files with 603 additions and 23 deletions.
40 changes: 40 additions & 0 deletions docs/modules/kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ The Kafka container will be started using a custom shell script:
[Init script](../../modules/kafka/kafka.go) inside_block:starterScript
<!--/codeinclude-->

That will set the advertised listeners with these values:

<!--codeinclude-->
[Advertised Listeners](../../modules/kafka/kafka.go) inside_block:advertisedListeners
<!--/codeinclude-->

KafkaContainer provides methods to read the broker addresses for different
connectivity environments.

#### Environment variables

The environment variables that are already set by default are:
Expand All @@ -82,3 +91,34 @@ The `Brokers(ctx)` method returns the Kafka brokers as a string slice, containin
<!--codeinclude-->
[Get Kafka brokers](../../modules/kafka/kafka_test.go) inside_block:getBrokers
<!--/codeinclude-->
#### BrokersByHostDockerInternal
The `BrokersByHostDockerInternal(ctx)` method returns the Kafka brokers as a
string slice, containing the hostname `host.docker.internal` and a random port
defined by Kafka's public port (`19092/tcp`).

This method is useful when you need to run additional containers that need to
connect to Kafka.

<!--codeinclude-->
[Get Kafka brokers by host.docker.internal](../../modules/kafka/examples_test.go) inside_block:getBrokersByHostDockerInternal
<!--/codeinclude-->

#### BrokersByContainerName

The `BrokersByContainerName(ctx)` method returns the Kafka brokers as a string
slice, addressed by the container's name(`Ex: charming_dijkstra:19093`). This
method is useful when you need to run additional containers that need to connect
to Kafka.
To use this broker address you should run all the containers inside a docker
network.
<!--codeinclude-->
[Start Kafka inside a docker network](../../modules/kafka/examples_test.go) inside_block:getBrokersByContainerName_Kafka
<!--/codeinclude-->
<!--codeinclude-->
[Get Kafka brokers by container name](../../modules/kafka/examples_test.go) inside_block:getBrokersByContainerName_Kcat
<!--/codeinclude-->
Loading

0 comments on commit 7395ce5

Please sign in to comment.