KubeMQ
Client SDKsC#How-to guidesManagement

List Channels

List all messaging channels on the KubeMQ server using the C# SDK management API.

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, client.ListChannelsAsync(type, searchPattern) queries channels of a given type and applies the optional searchPattern as a regular expression evaluated server-side, before results cross the wire. Each entry exposes Name, Type, and IsActive, reflecting whether a subscriber is currently connected.

Gotchas: because searchPattern is a real regex, literal characters like . need escaping (a verbatim string like @"orders\.us") or they'll match more than intended. IsActive and any traffic stats are a snapshot at call time, so a channel can go idle immediately after. And in production ListChannelsAsync will return channels created by other services and teams, not just your own — don't assume the result set is scoped to your application.

Prerequisites

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

Code

Program.cs
// KubeMQ .NET SDK — Management: List Channels with Search Filter
//
// This example demonstrates listing channels filtered by a regex pattern.
// The searchPattern parameter maps to the channel_search tag and is evaluated
// server-side as a regular expression.
//
// Prerequisites:
//   - KubeMQ server running on localhost:50000
//   - dotnet run

using KubeMQ.Sdk.Client;

await using var client = new KubeMQClient(new KubeMQClientOptions
{
    Address = "localhost:50000",
    ClientId = "csharp-config-list-channels-with-filter-client",
});
await client.ConnectAsync();
Console.WriteLine("Connected to KubeMQ server");

await client.CreateChannelAsync("csharp-demo.orders.us", "events");
await client.CreateChannelAsync("csharp-demo.orders.eu", "events");
await client.CreateChannelAsync("csharp-demo.payments", "events");
Console.WriteLine("Created sample channels");

Console.WriteLine("\n--- All 'events' channels ---");
var all = await client.ListChannelsAsync("events");
foreach (var ch in all)
{
    Console.WriteLine($"  {ch.Name}");
}

Console.WriteLine("\n--- Filtered: 'csharp-demo\\.orders.*' ---");
var filtered = await client.ListChannelsAsync("events", @"csharp-demo\.orders.*");
foreach (var ch in filtered)
{
    Console.WriteLine($"  {ch.Name}");
}

await client.DeleteChannelAsync("csharp-demo.orders.us", "events");
await client.DeleteChannelAsync("csharp-demo.orders.eu", "events");
await client.DeleteChannelAsync("csharp-demo.payments", "events");
Console.WriteLine("\nCleaned up sample channels");
Console.WriteLine("Done.");

How It Works

  • ListChannelsAsync("events") queries the server for all channels of the given type; an optional searchPattern parameter filters results server-side with a regular expression.
  • @"csharp-demo\.orders.*" is a verbatim string literal — the backslash escapes the literal dot in the channel name (so it does not match any character as a regex wildcard).
  • ch.Name, ch.Type, and ch.IsActive are the key fields on ChannelInfo; IsActive reflects whether any subscriber is currently connected.
  • The sample creates and then cleans up its own channels so the list output is deterministic; in production, ListChannelsAsync may return channels created by other services.

Was this page helpful?

On this page