KubeMQ
Client SDKsRubyHow-to guidesManagement

Delete Channel

Delete messaging channels from the KubeMQ broker with the Ruby SDK to clean up unused queues and pub/sub topics programmatically.

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

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

Code

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

  • 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.

Was this page helpful?

On this page