# Delete Channel (/sdks/java/how-to/management/delete-channel)



## Overview [#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, each client exposes typed delete methods scoped to what it manages — `PubSubClient.deleteEventsChannel(name)`, `QueuesClient.deleteQueuesChannel(name)`, and the equivalents on `CQClient` for commands and queries. 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 throws a `KubeMQException` rather than succeeding silently, so idempotent cleanup code needs a try/catch around the call. There's no "soft delete" or recovery window — once it's gone, any messages still queued are gone with it. And each client only manages its own channel family, so you need the matching client type (`PubSubClient`, `QueuesClient`, or `CQClient`) to delete a given channel — mismatching them won't work.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Java SDK installed (`implementation 'io.kubemq.sdk:kubemq-sdk-Java:3.1.1'` (Gradle) or Maven dependency from [Getting Started](/sdks/java))

## Code [#code]

```java title="DeleteChannelExample.java"
package io.kubemq.example.management;

import io.kubemq.sdk.cq.CQClient;
import io.kubemq.sdk.pubsub.PubSubClient;
import io.kubemq.sdk.queues.QueuesClient;

public class DeleteChannelExample {
    private static final String ADDRESS = "localhost:50000";
    private static final String CLIENT_ID = "java-management-delete-channel-client";

    public static void main(String[] args) {
        System.out.println("=== Delete Channels ===\n");

        // Create then delete an events channel
        try (PubSubClient pubsub = PubSubClient.builder().address(ADDRESS).clientId(CLIENT_ID).build()) {
            pubsub.createEventsChannel("java-management.delete-events-test");
            System.out.println("Created events channel.");
            pubsub.deleteEventsChannel("java-management.delete-events-test");
            System.out.println("Deleted events channel.");
        }

        // Create then delete a queues channel
        try (QueuesClient queues = QueuesClient.builder().address(ADDRESS).clientId(CLIENT_ID).build()) {
            queues.createQueuesChannel("java-management.delete-queues-test");
            System.out.println("Created queues channel.");
            queues.deleteQueuesChannel("java-management.delete-queues-test");
            System.out.println("Deleted queues channel.");
        }

        System.out.println("\nDelete channel examples completed.");
    }
}

```

## How It Works [#how-it-works]

* Each `delete*Channel` call sends a management RPC to the broker; the channel and any queued messages are removed immediately.
* The example first creates each channel so the delete always has something to act on; in production you would only call delete when decommissioning a channel.
* Deleting a non-existent channel throws a `KubeMQException` — wrap in try/catch if you need idempotent deletion.
* Each client lives in its own `try-with-resources` block so the gRPC connection closes right after the management calls complete.

## Related [#related]

* [Java SDK Reference](/sdks/java/reference)
* [Create Channel](/sdks/java/how-to/management/create-channel)
* [List Channels](/sdks/java/how-to/management/list-channels)
