# Channel Management (/learn/guides/channel-management)



<Callout type="info">
  For the conceptual model behind channels and how messages reach subscribers, see [Channels & Routing](/learn/concepts/channels-and-routing) in Fundamentals.
</Callout>

## Overview [#overview]

KubeMQ channels are created implicitly when a message is first published or subscribed to. However, you can also manage channels explicitly — creating, listing, deleting, and purging them through the SDK.

## Create Channel [#create-channel]

Create a channel before publishing to pre-register it with the server. The channel type must be specified: `events`, `events_store`, or `queues`.

<Tabs groupId="language" items="['Go', 'Python', 'Node.js', 'Java', 'C#', 'Kotlin', 'C++', 'Rust', 'Ruby', 'Elixir']">
  <Tab value="Go">
    ```go title="create_channel.go"
    package main

    import (
        "context"
        "log"

        "github.com/kubemq-io/kubemq-go/v2"
    )

    func main() {
        ctx := context.Background()
        client, err := kubemq.NewClient(ctx,
            kubemq.WithAddress("localhost", 50000),
        )
        if err != nil {
            log.Fatal(err)
        }
        defer client.Close()

        err = client.CreateChannel(ctx, "queues", "order-processing")
        if err != nil {
            log.Fatal(err)
        }
        log.Println("Channel created: order-processing")
    }
    ```
  </Tab>

  <Tab value="Python">
    ```python title="create_channel.py"
    from kubemq.queues import Client as QueuesClient

    client = QueuesClient(address="localhost:50000")

    client.create_channel("order-processing")
    print("Channel created: order-processing")
    client.close()
    ```
  </Tab>

  <Tab value="Node.js">
    ```javascript title="create_channel.js"
    const { KubeMQClient } = require("kubemq-js");

    const client = new KubeMQClient({ address: "localhost:50000" });

    await client.createChannel("queues", "order-processing");
    console.log("Channel created: order-processing");
    ```
  </Tab>

  <Tab value="Java">
    ```java title="CreateChannel.java"
    QueuesClient client = QueuesClient.builder()
        .address("localhost:50000")
        .clientId("admin-client")
        .build();

    client.createChannel("order-processing");
    System.out.println("Channel created: order-processing");
    client.close();
    ```
  </Tab>

  <Tab value="C#">
    ```csharp title="CreateChannel.cs"
    await using var client = new KubeMQClient(new KubeMQClientOptions
    {
        Address = "localhost:50000",
    });
    await client.ConnectAsync();

    await client.CreateChannelAsync("queues", "order-processing");
    Console.WriteLine("Channel created: order-processing");
    ```
  </Tab>

  <Tab value="Kotlin">
    ```kotlin title="CreateChannel.kt"
    val client = KubeMQClient.queues {
        address = "localhost:50000"
        clientId = "admin-client"
    }

    client.createChannel("order-processing")
    println("Channel created: order-processing")
    client.close()
    ```
  </Tab>

  <Tab value="C++">
    ```cpp title="create_channel.cpp"
    #include <kubemq/client.h>
    #include <iostream>

    kubemq::QueuesClient client("localhost:50000");

    client.createChannel("order-processing");
    std::cout << "Channel created: order-processing" << std::endl;
    ```
  </Tab>

  <Tab value="Rust">
    ```rust title="create_channel.rs"
    use kubemq::prelude::*;

    let client = KubemqClient::builder()
        .host("localhost")
        .port(50000)
        .build()
        .await?;

    client.create_queues_channel("order-processing").await?;
    println!("Channel created: order-processing");
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby title="create_channel.rb"
    require "kubemq"

    client = KubeMQ::QueuesClient.new(address: "localhost:50000", client_id: "admin-client")

    client.create_queues_channel(channel_name: "order-processing")
    puts "Channel created: order-processing"
    client.close
    ```
  </Tab>

  <Tab value="Elixir">
    ```elixir title="create_channel.exs"
    {:ok, client} = KubeMQ.Client.start_link(address: "localhost:50000", client_id: "admin-client")

    :ok = KubeMQ.Client.create_channel(client, "order-processing", :queues)
    IO.puts("Channel created: order-processing")
    KubeMQ.Client.close(client)
    ```
  </Tab>
</Tabs>

## Delete Channel [#delete-channel]

Remove a channel and its configuration from the server. Messages in the channel are discarded.

<Callout type="warn">
  Deleting a channel is irreversible. All pending messages in a queue channel are lost. Active subscriptions on the channel will receive an error.
</Callout>

<Tabs groupId="language" items="['Go', 'Python', 'Node.js', 'Java', 'C#', 'Kotlin', 'C++', 'Rust', 'Ruby', 'Elixir']">
  <Tab value="Go">
    ```go title="delete_channel.go"
    err = client.DeleteChannel(ctx, "queues", "order-processing")
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Channel deleted: order-processing")
    ```
  </Tab>

  <Tab value="Python">
    ```python title="delete_channel.py"
    client.delete_channel("order-processing")
    print("Channel deleted: order-processing")
    ```
  </Tab>

  <Tab value="Node.js">
    ```javascript title="delete_channel.js"
    await client.deleteChannel("queues", "order-processing");
    console.log("Channel deleted: order-processing");
    ```
  </Tab>

  <Tab value="Java">
    ```java title="DeleteChannel.java"
    client.deleteChannel("order-processing");
    System.out.println("Channel deleted: order-processing");
    ```
  </Tab>

  <Tab value="C#">
    ```csharp title="DeleteChannel.cs"
    await client.DeleteChannelAsync("queues", "order-processing");
    Console.WriteLine("Channel deleted: order-processing");
    ```
  </Tab>

  <Tab value="Kotlin">
    ```kotlin title="DeleteChannel.kt"
    client.deleteChannel("order-processing")
    println("Channel deleted: order-processing")
    ```
  </Tab>

  <Tab value="C++">
    ```cpp title="delete_channel.cpp"
    client.deleteChannel("order-processing");
    std::cout << "Channel deleted: order-processing" << std::endl;
    ```
  </Tab>

  <Tab value="Rust">
    ```rust title="delete_channel.rs"
    client.delete_queues_channel("order-processing").await?;
    println!("Channel deleted: order-processing");
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby title="delete_channel.rb"
    client.delete_queues_channel(channel_name: "order-processing")
    puts "Channel deleted: order-processing"
    ```
  </Tab>

  <Tab value="Elixir">
    ```elixir title="delete_channel.exs"
    :ok = KubeMQ.Client.delete_channel(client, "order-processing", :queues)
    IO.puts("Channel deleted: order-processing")
    ```
  </Tab>
</Tabs>

## List Channels [#list-channels]

Query the server for all active channels, optionally filtering by channel type or name pattern.

<Tabs groupId="language" items="['Go', 'Python', 'Node.js', 'Java', 'C#', 'Kotlin', 'C++', 'Rust', 'Ruby', 'Elixir']">
  <Tab value="Go">
    ```go title="list_channels.go"
    channels, err := client.ListChannels(ctx, "queues", "order")
    if err != nil {
        log.Fatal(err)
    }
    for _, ch := range channels {
        log.Printf("Channel: %s | Type: %s | Subscribers: %d | Messages: %d",
            ch.Name, ch.Type, ch.LastActivity, ch.Incoming)
    }
    ```
  </Tab>

  <Tab value="Python">
    ```python title="list_channels.py"
    channels = client.list_channels("order")

    for ch in channels:
        print(f"Channel: {ch.name} | Type: {ch.type} | Messages: {ch.incoming}")
    ```
  </Tab>

  <Tab value="Node.js">
    ```javascript title="list_channels.js"
    const channels = await client.listChannels("queues", "order");

    for (const ch of channels) {
      console.log(`Channel: ${ch.name} | Type: ${ch.type} | Messages: ${ch.incoming}`);
    }
    ```
  </Tab>

  <Tab value="Java">
    ```java title="ListChannels.java"
    List<ChannelInfo> channels = client.listChannels("order");

    for (ChannelInfo ch : channels) {
        System.out.printf("Channel: %s | Type: %s | Messages: %d%n",
            ch.getName(), ch.getType(), ch.getIncoming());
    }
    ```
  </Tab>

  <Tab value="C#">
    ```csharp title="ListChannels.cs"
    var channels = await client.ListChannelsAsync("queues", "order");

    foreach (var ch in channels)
    {
        Console.WriteLine($"Channel: {ch.Name} | Type: {ch.Type} | Messages: {ch.Incoming}");
    }
    ```
  </Tab>

  <Tab value="Kotlin">
    ```kotlin title="ListChannels.kt"
    val channels = client.listChannels("order")

    for (ch in channels) {
        println("Channel: ${ch.name} | Type: ${ch.type} | Messages: ${ch.incoming}")
    }
    ```
  </Tab>

  <Tab value="C++">
    ```cpp title="list_channels.cpp"
    auto channels = client.listChannels("order");

    for (const auto& ch : channels) {
        std::cout << "Channel: " << ch.name
                  << " | Type: " << ch.type
                  << " | Messages: " << ch.incoming << std::endl;
    }
    ```
  </Tab>

  <Tab value="Rust">
    ```rust title="list_channels.rs"
    use kubemq::channel_type;

    let channels = client.list_channels(channel_type::QUEUES, "order").await?;

    for ch in &channels {
        println!("Channel: {} | Active: {} | Last activity: {}",
            ch.name, ch.is_active, ch.last_activity);
    }
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby title="list_channels.rb"
    channels = client.list_queues_channels(search: "order")

    channels.each do |ch|
      puts "Channel: #{ch.name} | Active: #{ch.is_active} | Messages: #{ch.incoming}"
    end
    ```
  </Tab>

  <Tab value="Elixir">
    ```elixir title="list_channels.exs"
    {:ok, channels} = KubeMQ.Client.list_queues_channels(client, "order")

    Enum.each(channels, fn ch ->
      IO.puts("Channel: #{ch.name} | Active: #{ch.is_active} | Messages: #{ch.incoming}")
    end)
    ```
  </Tab>
</Tabs>

## Purge Queue [#purge-queue]

Remove all pending messages from a queue channel without deleting the channel itself. This is useful for clearing a backlog during development or after recovering from a failure.

<Callout type="warn">
  Purge permanently removes all messages from the queue. This cannot be undone.
</Callout>

<Tabs groupId="language" items="['Go', 'Python', 'Node.js', 'Java', 'C#', 'Kotlin', 'C++', 'Rust', 'Ruby', 'Elixir']">
  <Tab value="Go">
    ```go title="purge_queue.go"
    resp, err := client.PurgeQueue(ctx, "order-processing")
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Purged %d messages from order-processing", resp.MessagesCount)
    ```
  </Tab>

  <Tab value="Python">
    ```python title="purge_queue.py"
    result = client.purge_queue("order-processing")
    print(f"Purged {result.messages_count} messages from order-processing")
    ```
  </Tab>

  <Tab value="Node.js">
    ```javascript title="purge_queue.js"
    const result = await client.purgeQueue("order-processing");
    console.log(`Purged ${result.messagesCount} messages from order-processing`);
    ```
  </Tab>

  <Tab value="Java">
    ```java title="PurgeQueue.java"
    PurgeResult result = client.purgeQueue("order-processing");
    System.out.printf("Purged %d messages from order-processing%n", result.getMessagesCount());
    ```
  </Tab>

  <Tab value="C#">
    ```csharp title="PurgeQueue.cs"
    var result = await client.PurgeQueueAsync("order-processing");
    Console.WriteLine($"Purged {result.MessagesCount} messages from order-processing");
    ```
  </Tab>

  <Tab value="Kotlin">
    ```kotlin title="PurgeQueue.kt"
    val result = client.purgeQueue("order-processing")
    println("Purged ${result.messagesCount} messages from order-processing")
    ```
  </Tab>

  <Tab value="C++">
    ```cpp title="purge_queue.cpp"
    auto result = client.purgeQueue("order-processing");
    std::cout << "Purged " << result.messagesCount << " messages from order-processing"
              << std::endl;
    ```
  </Tab>

  <Tab value="Rust">
    ```rust title="purge_queue.rs"
    // The Rust SDK purges a queue by acking all pending messages.
    client.ack_all_queue_messages("order-processing").await?;
    println!("Purged all messages from order-processing");
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby title="purge_queue.rb"
    client.purge_queue_channel(channel_name: "order-processing")
    puts "Purged all messages from order-processing"
    ```
  </Tab>

  <Tab value="Elixir">
    ```elixir title="purge_queue.exs"
    :ok = KubeMQ.Client.purge_queue_channel(client, "order-processing")
    IO.puts("Purged all messages from order-processing")
    ```
  </Tab>
</Tabs>

## Key Points [#key-points]

* **Implicit creation** — channels are automatically created on first use (publish or subscribe)
* **Explicit management** — use the SDK for administrative operations like cleanup or provisioning
* **Type-scoped** — create and list operations require specifying the channel type (`events`, `events_store`, or `queues`)
* **Purge is queue-only** — only queue channels support purging; events and events\_store channels have different lifecycle semantics

## Next Steps [#next-steps]

<Cards>
  <Card title="Channel Routing" href="/learn/guides/channel-routing" description="Route messages across multiple channels and patterns." />

  <Card title="Production Checklist" href="/learn/guides/production-checklist" description="Verify channel configuration before deployment." />
</Cards>
