Skip to content

Commit f89132c

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

File tree

4 files changed

+625
-30
lines changed

4 files changed

+625
-30
lines changed

docs/modules/kafka.md

Lines changed: 39 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,33 @@ 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:<random_port>`.
99+
100+
This method is useful when you need to run additional containers that need to
101+
connect to Kafka.
102+
103+
<!--codeinclude-->
104+
[Get Kafka brokers by host.docker.internal](../../modules/kafka/examples_test.go) inside_block:getBrokersByHostDockerInternal
105+
<!--/codeinclude-->
106+
107+
#### BrokersByContainerName
108+
109+
The `BrokersByContainerName(ctx)` method returns the Kafka brokers as a string
110+
slice, addressed by the container's name(`Ex: charming_dijkstra:19093`). This
111+
method is useful when you need to run additional containers that need to connect
112+
to Kafka.
113+
114+
To use this broker address you should run all the containers inside a docker
115+
network.
116+
117+
<!--codeinclude-->
118+
[First start Kafka inside a docker network](../../modules/kafka/examples_test.go) inside_block:getBrokersByContainerName_Kafka
119+
<!--/codeinclude-->
120+
121+
<!--codeinclude-->
122+
[Then start a second container in the same network](../../modules/kafka/examples_test.go) inside_block:getBrokersByContainerName_Kcat
123+
<!--/codeinclude-->

0 commit comments

Comments
 (0)