KubeMQ
Client SDKsC#How-to guidesManagement

Delete Channel

Delete an existing KubeMQ messaging channel programmatically using the C# SDK management 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's routing table 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, client.DeleteChannelAsync(name, type) sends a management call that removes the channel by name and type. The type argument must match the type the channel was created with — channels are namespaced by type, so "events" and "events_store" are distinct namespaces, and an events channel can share a name with a queues channel without colliding.

Gotchas: unlike some SDKs, deleting a non-existent channel here returns success rather than an error — the operation is idempotent, which is convenient for cleanup scripts but means you can't rely on the call failing to detect a missing channel. There's no "soft delete" or recovery window — any messages still queued are gone the moment deletion completes. And after deletion, connected subscribers and publishers aren't notified proactively; they'll only see a ChannelNotFound error on their next call against the channel.

Prerequisites

  • KubeMQ server running on localhost:50000
  • C# SDK installed (dotnet add package KubeMQ.SDK.CSharp)

Code

Program.cs
// KubeMQ .NET SDK — Management: Delete Channel
//
// This example demonstrates deleting a channel with the management API.
// The channel is created first so there's something to delete.
//
// Prerequisites:
//   - KubeMQ server running on localhost:50000
//   - dotnet run

using KubeMQ.Sdk.Client;

await using var client = new KubeMQClient(new KubeMQClientOptions
{
    ClientId = "csharp-config-channel-management-client",
});
await client.ConnectAsync();

Console.WriteLine("Connected to KubeMQ server");

await client.CreateChannelAsync("csharp-config.channel-management", "events");
Console.WriteLine("Channel 'csharp-config.channel-management' created.");

await client.DeleteChannelAsync("csharp-config.channel-management", "events");
Console.WriteLine("Channel 'csharp-config.channel-management' deleted.");

Console.WriteLine("Done.");

How It Works

  • DeleteChannelAsync(name, type) unregisters the channel from the server's routing table; the type argument must match the channel type it was created with.
  • After deletion, any subscriber still connected to the channel will receive an error on its next receive call; publishers will get a ChannelNotFound error.
  • Deleting a non-existent channel returns success — the operation is idempotent.
  • Always match the channel type string exactly; "events" and "events_store" are distinct namespaces on the broker.
  • The channel is created here only to give the example something to delete — see Create Channel for the create-only flow.

Was this page helpful?

On this page