# List Channels (/sdks/elixir/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, `KubeMQ.Client.list_channels/3` queries channels of a given type and returns `{:ok, [%ChannelInfo{}]}` on success; convenience functions like `list_queues_channels/2` wrap the same call with an optional filter string applied server-side. Each `ChannelInfo` struct carries `name`, `is_active`, and `incoming`/`outgoing` message counts.

**Gotchas:** the filter is a prefix/substring match, not a glob or regex — there's no wildcard syntax to anchor or exclude. Every call returns a tagged tuple (`{:ok, _}` or `{:error, _}`) rather than raising, so pattern-match on the result instead of wrapping calls in `try`/`rescue`. And `is_active` plus the traffic counters are a snapshot at query time, so a channel can go idle immediately after.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Elixir SDK installed (`{:kubemq, "~> 1.0"}` in mix.exs)

## Code [#code]

```elixir title="main.exs"
{:ok, client} = KubeMQ.Client.start_link(address: "localhost:50000", client_id: "elixir-mgmt-list")

for type <- [:events, :events_store, :commands, :queries, :queues] do
  case KubeMQ.Client.list_channels(client, type) do
    {:ok, channels} ->
      IO.puts("\n#{type} channels (#{length(channels)}):")

      Enum.each(channels, fn ch ->
        IO.puts("  - #{ch.name} (active: #{ch.is_active}, in: #{ch.incoming}, out: #{ch.outgoing})")
      end)

    {:error, err} ->
      IO.puts("\n#{type}: #{err.message}")
  end
end

IO.puts("\n--- Filtered search ---")

case KubeMQ.Client.list_queues_channels(client, "elixir-mgmt") do
  {:ok, channels} ->
    IO.puts("Queue channels matching 'elixir-mgmt': #{length(channels)}")

  {:error, err} ->
    IO.puts("Search failed: #{err.message}")
end

KubeMQ.Client.close(client)
```

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

* `list_channels/3` returns `{:ok, [%ChannelInfo{}]}` with channel metadata
* Each `ChannelInfo` includes `name`, `is_active`, `incoming`, and `outgoing` message counts
* Convenience functions like `list_queues_channels/2` accept an optional filter string

## Related [#related]

* [Create Channel](/sdks/elixir/how-to/management/create-channel)
* [Delete Channel](/sdks/elixir/how-to/management/delete-channel)
