From bfa5b8c5706c8d107580f9a03562ed76f3566e86 Mon Sep 17 00:00:00 2001 From: Santiago Jimenez Giraldo Date: Wed, 10 Jan 2024 21:18:23 +0100 Subject: [PATCH] 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 --- docs/modules/redpanda.md | 20 ++++++++++++++++++++ modules/redpanda/redpanda_test.go | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/modules/redpanda.md b/docs/modules/redpanda.md index c7d8cd36d9..ad2223ce83 100644 --- a/docs/modules/redpanda.md +++ b/docs/modules/redpanda.md @@ -51,6 +51,26 @@ for Redpanda. E.g. `testcontainers.WithImage("docker.redpanda.com/redpandadata/r If you need to enable TLS use `WithTLS` with a valid PEM encoded certificate and key. +#### Additional Listener + +There are scenarios where additional listeners are needed, for example if you +want to consume/from another container in the same network + +You can use the `WithListener` option to add a listener to the Redpanda container. + +[Register additional listener](../../modules/redpanda/redpanda_test.go) inside_block:withListenerRP + + +Container defined in the same network + +[Start Kcat container](../../modules/redpanda/redpanda_test.go) inside_block:withListenerKcat + + +Produce messages using the new registered listener + +[Produce/consume via registered listener](../../modules/redpanda/redpanda_test.go) inside_block:withListenerExec + + ### Container Methods The Redpanda container exposes the following methods: diff --git a/modules/redpanda/redpanda_test.go b/modules/redpanda/redpanda_test.go index a8cedc1589..95a1c0ca33 100644 --- a/modules/redpanda/redpanda_test.go +++ b/modules/redpanda/redpanda_test.go @@ -283,19 +283,23 @@ func TestRedpandaWithTLS(t *testing.T) { func TestRedpandaListener_Simple(t *testing.T) { ctx := context.Background() + // 1. Create network rpNetwork, err := network.New(ctx, network.WithCheckDuplicate()) require.NoError(t, err) // 2. Start Redpanda container + // withListenerRP { container, err := RunContainer(ctx, testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), network.WithNetwork([]string{"redpanda-host"}, rpNetwork), WithListener("redpanda:29092"), WithAutoCreateTopics(), ) + // } require.NoError(t, err) // 3. Start KCat container + // withListenerKcat { kcat, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ Image: "confluentinc/cp-kcat:7.4.1", @@ -312,6 +316,7 @@ func TestRedpandaListener_Simple(t *testing.T) { }, Started: true, }) + // } require.NoError(t, err) @@ -319,8 +324,10 @@ func TestRedpandaListener_Simple(t *testing.T) { err = kcat.CopyToContainer(ctx, []byte("Message produced by kcat"), "/tmp/msgs.txt", 700) require.NoError(t, err) - // 5. Produce mesaage to Redpanda + // 5. Produce message to Redpanda + // withListenerExec { _, _, err = kcat.Exec(ctx, []string{"kcat", "-b", "redpanda:29092", "-t", "msgs", "-P", "-l", "/tmp/msgs.txt"}) + // } require.NoError(t, err)