KubeMQ
Client SDKsRustHow-to guidesManagement

List Channels

List KubeMQ channels by type with an optional search filter and read their statistics using the Rust SDK.

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.list_channels(channel_type, search) queries channels of a given type and narrows results server-side to names matching the optional search string; the typed helper list_events_channels("") skips the explicit channel_type::* constant. Each result is a ChannelInfo with name, activity status, and message statistics.

Gotchas: the search filter is a substring match, not a glob or regex — there's no wildcard syntax to anchor or exclude. An empty search string lists every channel of that type, which can be a heavy call on a broker with many channels. And is_active and the statistics fields are a snapshot at call time, so a channel can go idle immediately after the response returns.

Prerequisites

  • KubeMQ server running on localhost:50000
  • Rust SDK installed (cargo add kubemq)

Code

main.rs
use kubemq::channel_type;
use kubemq::prelude::*;

#[tokio::main]
async fn main() -> kubemq::Result<()> {
    let client = KubemqClient::builder()
        .host("localhost")
        .port(50000)
        .build()
        .await?;

    let events_channels = client.list_events_channels("").await?;
    println!("Events channels: {}", events_channels.len());
    for ch in &events_channels {
        println!(
            "  name={}, active={}, last_activity={}",
            ch.name, ch.is_active, ch.last_activity
        );
    }

    let filtered = client.list_channels(channel_type::QUEUES, "example").await?;
    println!("Filtered queues channels: {}", filtered.len());

    client.close().await?;
    Ok(())
}

How It Works

  • list_channels accepts a channel type and optional search filter string.
  • An empty search string lists all channels of the specified type.
  • Returns ChannelInfo with name, type, activity status, and message statistics.
  • Review timeouts, channel names, and client IDs before running against shared environments.
  • Run the program while the server from the prerequisites is available.

Was this page helpful?

On this page