Skip to content

Commit 7395ce5

Browse files
committed
feat: additional advertised listners/broker addresses for kafka
1 parent 35bf0cd commit 7395ce5

File tree

4 files changed

+603
-23
lines changed

4 files changed

+603
-23
lines changed

docs/modules/kafka.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ The Kafka container will be started using a custom shell script:
6161
[Init script](../../modules/kafka/kafka.go) inside_block:starterScript
6262
<!--/codeinclude-->
6363

64+
That will set the advertised listeners with these values:
65+
66+
<!--codeinclude-->
67+
[Advertised Listeners](../../modules/kafka/kafka.go) inside_block:advertisedListeners
68+
<!--/codeinclude-->
69+
70+
KafkaContainer provides methods to read the broker addresses for different
71+
connectivity environments.
72+
6473
#### Environment variables
6574

6675
The environment variables that are already set by default are:
@@ -82,3 +91,34 @@ The `Brokers(ctx)` method returns the Kafka brokers as a string slice, containin
8291
<!--codeinclude-->
8392
[Get Kafka brokers](../../modules/kafka/kafka_test.go) inside_block:getBrokers
8493
<!--/codeinclude-->
94+
95+
#### BrokersByHostDockerInternal
96+
97+
The `BrokersByHostDockerInternal(ctx)` method returns the Kafka brokers as a
98+
string slice, containing the hostname `host.docker.internal` and a random port
99+
defined by Kafka's public port (`19092/tcp`).
100+
101+
This method is useful when you need to run additional containers that need to
102+
connect to Kafka.
103+
104+
<!--codeinclude-->
105+
[Get Kafka brokers by host.docker.internal](../../modules/kafka/examples_test.go) inside_block:getBrokersByHostDockerInternal
106+
<!--/codeinclude-->
107+
108+
#### BrokersByContainerName
109+
110+
The `BrokersByContainerName(ctx)` method returns the Kafka brokers as a string
111+
slice, addressed by the container's name(`Ex: charming_dijkstra:19093`). This
112+
method is useful when you need to run additional containers that need to connect
113+
to Kafka.
114+
115+
To use this broker address you should run all the containers inside a docker
116+
network.
117+
118+
<!--codeinclude-->
119+
[Start Kafka inside a docker network](../../modules/kafka/examples_test.go) inside_block:getBrokersByContainerName_Kafka
120+
<!--/codeinclude-->
121+
122+
<!--codeinclude-->
123+
[Get Kafka brokers by container name](../../modules/kafka/examples_test.go) inside_block:getBrokersByContainerName_Kcat
124+
<!--/codeinclude-->

0 commit comments

Comments
 (0)