KubeMQ
Client SDKsNode.jsHow-to guidesManagement

Delete Channel

Delete an existing KubeMQ messaging channel programmatically with the Node.js SDK to clean up unused queues and pub/sub topics.

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, client.deleteChannel(name, type) sends a management call that removes the channel by name and type. The type argument matters — channels are namespaced by type, so an events channel and a queues channel can share the same name without colliding, and deleting one never touches the other; the type you pass must match the type used when the channel was created.

Gotchas: deletion is permanent and unrecoverable — there's no "soft delete," so any messages still queued are gone the moment the call succeeds. Passing the wrong type string for an existing channel name won't delete anything, it'll just look like a no-op or return a not-found error depending on the server. And because deletion doesn't ask for confirmation, production scripts should call listChannels() first to confirm the channel actually exists (and is the one you mean) before deleting it.

Prerequisites

  • KubeMQ server running on localhost:50000
  • Node.js SDK installed (npm install kubemq-js)

Code

delete-channel.ts
import { KubeMQClient } from 'kubemq-js';

async function main() {
  const client = await KubeMQClient.create({
    address: 'localhost:50000',
    clientId: 'js-management-delete-channel-client',
  });

  try {
    const eventsChannel = 'js-management.delete-channel-events';
    await client.deleteChannel(eventsChannel, 'events');
    console.log('Deleted events channel:', eventsChannel);

    const queuesChannel = 'js-management.delete-channel-queues';
    await client.deleteChannel(queuesChannel, 'queues');
    console.log('Deleted queues channel:', queuesChannel);
  } finally {
    await client.close();
  }
}

main().catch(console.error);

How It Works

  • client.deleteChannel(name, type) removes a channel from the server; undelivered messages in the channel are discarded.
  • The channel type must match the type used at creation — deleting an 'events' channel does not affect a 'queues' channel of the same name.
  • Deletion is permanent and unrecoverable; use listChannels() first to confirm the channel exists before deleting in production scripts.

Was this page helpful?

On this page