Delete Channel
Delete an existing KubeMQ channel by name and type using the Elixir SDK admin API.
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, KubeMQ.Client.delete_channel/3 takes the channel name and type and sends a management call that removes it; convenience aliases like delete_events_store_channel/2 do the same thing without requiring the type atom. 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: deleting a non-existent channel returns {:error, err} rather than raising, so pattern-match on the result if your cleanup code needs to tolerate a channel that's already gone. There's no "soft delete" or recovery window — any messages still queued are gone the moment the call returns :ok. And passing the wrong type atom for an existing channel name won't delete it — you'll get a not-found error even though a channel with that name exists under a different type.
Prerequisites
- KubeMQ server running on
localhost:50000 - Elixir SDK installed (
{:kubemq, "~> 1.0"}in mix.exs)
Code
{:ok, client} = KubeMQ.Client.start_link(address: "localhost:50000", client_id: "elixir-mgmt-delete")
channel_name = "elixir-mgmt.delete-channel"
:ok = KubeMQ.Client.create_channel(client, channel_name, :events)
IO.puts("Created channel '#{channel_name}'")
case KubeMQ.Client.delete_channel(client, channel_name, :events) do
:ok -> IO.puts("Deleted channel '#{channel_name}'")
{:error, err} -> IO.puts("Delete failed: #{err.message}")
end
:ok = KubeMQ.Client.create_events_store_channel(client, "elixir-mgmt.delete-channel-es")
case KubeMQ.Client.delete_events_store_channel(client, "elixir-mgmt.delete-channel-es") do
:ok -> IO.puts("Deleted events store channel via convenience alias")
{:error, err} -> IO.puts("Delete failed: #{err.message}")
end
KubeMQ.Client.close(client)How It Works
delete_channel/3accepts the channel name and type- Convenience functions like
delete_events_store_channel/2simplify type-specific operations - Deleting a channel removes it and any associated data from the server
Related
Was this page helpful?