# Delete Channel (/sdks/ruby/how-to/management/delete-channel)



## Overview [#overview]

Deleting a channel is how you decommission a topic, queue, or RPC endpoint you no longer need — tearing down test fixtures between CI runs, retiring a deprecated integration, or cleaning up the throwaway channels a demo or load test created. It's a permanent, immediate operation: the channel's routing entry is removed from the broker and any messages still sitting in it are discarded, so it's not something you want triggered by a typo in a shared environment.

Under the hood, `delete_events_channel(channel_name:)` (and its counterparts on the other client types) sends a management call that removes the channel by name. Because channels are namespaced by type, an events channel and a queues channel can share the same name without colliding, and deleting one never touches the other.

**Gotchas:** channel deletion is permanent — all associated data is removed from the broker with no "soft delete" or recovery window, so any messages still queued are gone the moment the call succeeds. There's no confirmation step, so it's worth calling `list_channels` with a search filter before and after to verify you deleted the channel you meant to. And running this against a shared environment with the wrong channel name or client ID can silently remove a channel other services still depend on.

## 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-delete-example')
  puts "Connected to #{address}"

  pubsub.create_events_channel(channel_name: 'mgmt.delete.test')
  puts 'Created channel: mgmt.delete.test'

  channels = pubsub.list_events_channels(search: 'mgmt.delete')
  puts "Before delete: #{channels.size} channel(s) found"

  pubsub.delete_events_channel(channel_name: 'mgmt.delete.test')
  puts 'Deleted channel: mgmt.delete.test'

  channels = pubsub.list_events_channels(search: 'mgmt.delete')
  puts "After delete: #{channels.size} channel(s) found"
rescue KubeMQ::Error => e
  puts "KubeMQ error: #{e.message}"
ensure
  pubsub&.close
  puts 'Done'
end
```

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

* Channel deletion is permanent — all associated data is removed from the broker.
* Use `list_channels` with a search filter to verify deletion.
* 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)
* [List Channels](/sdks/ruby/how-to/management/list-channels)
