# List Channels (/sdks/ruby/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, each client exposes convenience methods for its own channel types — `list_events_channels`, `list_events_store_channels`, `list_queues_channels`, `list_commands_channels`, `list_queries_channels` — and every one accepts an optional `search:` keyword that filters names by substring match, server-side. Each result is an array of `ChannelInfo` objects carrying the channel's name and activity metadata.

**Gotchas:** listing is scoped per client — `pubsub` only sees events and events-store channels, `queues` only sees queues, `cq` only sees commands and queries — so a full inventory across all types means calling all three. The `search` filter is a substring match, not a glob or regex, so there's no wildcard syntax to anchor or exclude. And the metadata returned is a snapshot at call time — treat it as a point-in-time read, not a live subscription to channel state.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Ruby SDK installed (`gem install kubemq`)

## Code [#code]

```ruby title="main.rb"
require 'kubemq'

address = ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000')

begin
  pubsub = KubeMQ::PubSubClient.new(address: address, client_id: 'mgmt-list-example')
  queues = KubeMQ::QueuesClient.new(address: address, client_id: 'mgmt-list-example')
  cq = KubeMQ::CQClient.new(address: address, client_id: 'mgmt-list-example')
  puts "Connected to #{address}"

  puts "\n--- Events Channels ---"
  pubsub.list_events_channels.each { |ch| puts "  #{ch}" }

  puts "\n--- Events Store Channels ---"
  pubsub.list_events_store_channels.each { |ch| puts "  #{ch}" }

  puts "\n--- Queue Channels ---"
  queues.list_queues_channels.each { |ch| puts "  #{ch}" }

  puts "\n--- Command Channels ---"
  cq.list_commands_channels.each { |ch| puts "  #{ch}" }

  puts "\n--- Query Channels ---"
  cq.list_queries_channels.each { |ch| puts "  #{ch}" }

  puts "\n--- Filtered Search (search='mgmt') ---"
  filtered = pubsub.list_events_channels(search: 'mgmt')
  filtered.each { |ch| puts "  #{ch}" }
  puts "Found #{filtered.size} matching channel(s)"
rescue KubeMQ::Error => e
  puts "KubeMQ error: #{e.message}"
ensure
  pubsub&.close
  queues&.close
  cq&.close
  puts 'Done'
end
```

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

* Each client provides convenience methods to list channels for its supported types.
* The `search` parameter filters channel names by substring match.
* Returns an array of `ChannelInfo` objects with channel metadata.
* Review timeouts, channel names, and client IDs before running against shared environments.

## Related [#related]

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