Skip to content

Commit 5064d3b

Browse files
committed
docs: add documentation for WithListener option Redpanda
Add documentation for the additional listener option (WithListener) for the Redpanda module Signed-off-by: Santiago Jimenez Giraldo <[email protected]>
1 parent 2b99c03 commit 5064d3b

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

docs/modules/redpanda.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ for Redpanda. E.g. `testcontainers.WithImage("docker.redpanda.com/redpandadata/r
5151

5252
If you need to enable TLS use `WithTLS` with a valid PEM encoded certificate and key.
5353

54+
#### Additional Listener
55+
56+
There are scenarios where additional listeners are needed, for example if you
57+
want to consume/from another container in the same network
58+
59+
You can use the `WithListener` option to add a listener to the Redpanda container.
60+
<!--codeinclude-->
61+
[Register additional listener](../../modules/redpanda/redpanda_test.go) inside_block:withListenerRP
62+
<!--/codeinclude-->
63+
64+
Container defined in the same network
65+
<!--codeinclude-->
66+
[Start Kcat container](../../modules/redpanda/redpanda_test.go) inside_block:withListenerKcat
67+
<!--/codeinclude-->
68+
69+
Produce messages using the new registered listener
70+
<!--codeinclude-->
71+
[Produce/consume via registered listener](../../modules/redpanda/redpanda_test.go) inside_block:withListenerExec
72+
<!--/codeinclude-->
73+
5474
### Container Methods
5575

5676
The Redpanda container exposes the following methods:

modules/redpanda/redpanda_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,22 @@ func TestRedpandaWithTLS(t *testing.T) {
284284
func TestRedpandaListener_Simple(t *testing.T) {
285285
ctx := context.Background()
286286

287-
<<<<<<< Updated upstream
288287
// 1. Create network
289-
RPNetwork, err := network.New(ctx, network.WithCheckDuplicate())
290-
=======
291-
// 1. Create network
292288
rpNetwork, err := network.New(ctx, network.WithCheckDuplicate())
293-
>>>>>>> Stashed changes
294289
require.NoError(t, err)
295290

296291
// 2. Start Redpanda container
292+
// withListenerRP {
297293
container, err := RunContainer(ctx,
298294
testcontainers.WithImage("redpandadata/redpanda:v23.2.18"),
299295
network.WithNetwork([]string{"redpanda-host"}, rpNetwork),
300296
WithListener("redpanda:29092"), WithAutoCreateTopics(),
301297
)
298+
// }
302299
require.NoError(t, err)
303300

304301
// 3. Start KCat container
302+
// withListenerKcat {
305303
kcat, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
306304
ContainerRequest: testcontainers.ContainerRequest{
307305
Image: "confluentinc/cp-kcat:7.4.1",
@@ -318,15 +316,18 @@ func TestRedpandaListener_Simple(t *testing.T) {
318316
},
319317
Started: true,
320318
})
319+
// }
321320

322321
require.NoError(t, err)
323322

324323
// 4. Copy message to kcat
325324
err = kcat.CopyToContainer(ctx, []byte("Message produced by kcat"), "/tmp/msgs.txt", 700)
326325
require.NoError(t, err)
327326

328-
// 5. Produce mesaage to Redpanda
327+
// 5. Produce message to Redpanda
328+
// withListenerExec {
329329
_, _, err = kcat.Exec(ctx, []string{"kcat", "-b", "redpanda:29092", "-t", "msgs", "-P", "-l", "/tmp/msgs.txt"})
330+
// }
330331

331332
require.NoError(t, err)
332333

0 commit comments

Comments
 (0)