# List Channels (/sdks/go/how-to/management/list-channels)



## Overview [#overview]

Listing channels turns the broker into a discoverable inventory instead of a black box — instead of hardcoding channel names everywhere, you ask the server what actually exists right now. That's exactly what monitoring dashboards, cleanup scripts, and "did my deployment create the channels it should have" checks need. It's read-only and has no effect on message flow, so it's safe to run against production at any time.

Under the hood, `client.ListChannels(ctx, channelType, searchQuery)` queries channels of one type — events, events-store, queues, commands, or queries — and an optional `searchQuery` narrows results server-side by substring instead of filtering client-side. Typed helpers like `ListEventsChannels` and `ListQueuesChannels` wrap the same call without the `ChannelType` constant. Each result includes the name, an `IsActive` flag, and traffic statistics.

**Gotchas:** the search filter is a substring match, not a glob or regex. `IsActive` and the stat counters are a snapshot at query time, so a channel can go idle a moment later. And no matches returns an empty slice, not an error — check length rather than an exception path.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Go SDK installed (`go get github.com/kubemq-io/kubemq-go/v2`)

## Code [#code]

```go title="main.go"
// Example: management/list-channels
//
// Demonstrates listing channels with optional search filter.
// You can list all channels of a type or filter by name prefix.
//
// Channel: go-management.list-channels
// Client ID: go-management-list-channels-client
//
// Run with a KubeMQ server on localhost:50000
// (see https://docs.kubemq.io/deploy).
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/kubemq-io/kubemq-go/v2"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	client, err := kubemq.NewClient(ctx,
		kubemq.WithAddress("localhost", 50000),
		kubemq.WithClientId("go-management-list-channels-client"),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	// List all events channels.
	channels, err := client.ListChannels(ctx, kubemq.ChannelTypeEvents, "")
	if err != nil {
		log.Println("ListChannels:", err)
	} else {
		fmt.Printf("All events channels: %d found\n", len(channels))
		for _, ch := range channels {
			fmt.Printf("  - %s (active=%v)\n", ch.Name, ch.IsActive)
		}
	}

	// List channels with a search filter.
	filtered, err := client.ListChannels(ctx, kubemq.ChannelTypeQueues, "go-")
	if err != nil {
		log.Println("ListChannels filtered:", err)
	} else {
		fmt.Printf("Queue channels matching 'go-': %d found\n", len(filtered))
		for _, ch := range filtered {
			fmt.Printf("  - %s\n", ch.Name)
		}
	}

	// Typed convenience methods — no channel-type constant needed.
	eventsChannels, err := client.ListEventsChannels(ctx, "")
	if err != nil {
		log.Println("ListEventsChannels:", err)
	} else {
		fmt.Printf("Events channels (typed): %d found\n", len(eventsChannels))
		for _, ch := range eventsChannels {
			fmt.Printf("  - %s (active=%v)\n", ch.Name, ch.IsActive)
		}
	}

	queuesChannels, err := client.ListQueuesChannels(ctx, "go-")
	if err != nil {
		log.Println("ListQueuesChannels:", err)
	} else {
		fmt.Printf("Queue channels (typed, matching 'go-'): %d found\n", len(queuesChannels))
		for _, ch := range queuesChannels {
			fmt.Printf("  - %s\n", ch.Name)
		}
	}
}

```

## How It Works [#how-it-works]

1. `client.ListChannels(ctx, channelType, searchQuery)` returns a `[]*ChannelInfo` slice; an empty `searchQuery` string returns all channels of that type.
2. Passing `"go-"` as the search query filters to channels whose names contain that prefix, reducing the result set on servers with many channels.
3. Each `ChannelInfo` item includes `Name`, `IsActive` (has active subscribers), and additional statistics fields like message counts and last activity timestamps.
4. The typed helpers (`ListEventsChannels`, `ListQueuesChannels`, etc.) remove the need for the `ChannelType` constant and are the recommended API for type-safe code.

## Related [#related]

* [Go SDK Reference](/sdks/go/reference)
* [Create Channel](/sdks/go/how-to/management/create-channel)
* [Delete Channel](/sdks/go/how-to/management/delete-channel)
