Skip to content

Commit

Permalink
docs: add documentation for WithListener option Redpanda
Browse files Browse the repository at this point in the history
Add documentation for the additional listener option (WithListener) for the
Redpanda module

Signed-off-by: Santiago Jimenez Giraldo <sago2k8@gmail.com>
  • Loading branch information
sago2k8 committed Jan 11, 2024
1 parent 2f395bd commit bfa5b8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/modules/redpanda.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<!--codeinclude-->
[Register additional listener](../../modules/redpanda/redpanda_test.go) inside_block:withListenerRP
<!--/codeinclude-->

Container defined in the same network
<!--codeinclude-->
[Start Kcat container](../../modules/redpanda/redpanda_test.go) inside_block:withListenerKcat
<!--/codeinclude-->

Produce messages using the new registered listener
<!--codeinclude-->
[Produce/consume via registered listener](../../modules/redpanda/redpanda_test.go) inside_block:withListenerExec
<!--/codeinclude-->

### Container Methods

The Redpanda container exposes the following methods:
Expand Down
9 changes: 8 additions & 1 deletion modules/redpanda/redpanda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -312,15 +316,18 @@ func TestRedpandaListener_Simple(t *testing.T) {
},
Started: true,
})
// }

require.NoError(t, err)

// 4. Copy message to kcat
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)

Expand Down

0 comments on commit bfa5b8c

Please sign in to comment.