List Channels
List all active KubeMQ channels on the server with the Java SDK administration API to inspect Events, Queues, and more.
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, each channel type has its own list method — listEventsChannels, listEventsStoreChannels, listQueuesChannels, listCommandsChannels, listQueriesChannels — each taking a search prefix and returning typed objects (PubSubChannel, QueuesChannel, CQChannel). Only names starting with that prefix come back, making it easy to scope a listing to one SDK or environment. Each object exposes getName() plus active-subscriber count and last-activity timestamp.
Gotchas: the prefix filter is a startswith match, not a glob or regex — there's no way to match a suffix or exclude a pattern. An empty prefix ("") lists everything of that type, which can be a heavy call on a broker with many channels, so scope it whenever you can. And the list methods are split by client — PubSubClient for events/events-store, QueuesClient for queues, CQClient for commands/queries — so a full inventory means querying all three.
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)
Code
package io.kubemq.example.management;
import io.kubemq.sdk.cq.CQChannel;
import io.kubemq.sdk.cq.CQClient;
import io.kubemq.sdk.pubsub.PubSubChannel;
import io.kubemq.sdk.pubsub.PubSubClient;
import io.kubemq.sdk.queues.QueuesChannel;
import io.kubemq.sdk.queues.QueuesClient;
import java.util.List;
public class ListChannelsExample {
private static final String ADDRESS = "localhost:50000";
private static final String CLIENT_ID = "java-management-list-channels-client";
public static void main(String[] args) {
System.out.println("=== List Channels ===\n");
// List PubSub channels (events and events-store)
try (PubSubClient pubsub = PubSubClient.builder().address(ADDRESS).clientId(CLIENT_ID + "-pubsub").build()) {
List<PubSubChannel> events = pubsub.listEventsChannels("java-");
System.out.println("Events channels (" + events.size() + "):");
events.forEach(ch -> System.out.println(" " + ch.getName()));
List<PubSubChannel> stores = pubsub.listEventsStoreChannels("java-");
System.out.println("EventsStore channels (" + stores.size() + "):");
stores.forEach(ch -> System.out.println(" " + ch.getName()));
}
// List Queues channels
try (QueuesClient queues = QueuesClient.builder().address(ADDRESS).clientId(CLIENT_ID + "-queues").build()) {
List<QueuesChannel> qChs = queues.listQueuesChannels("java-");
System.out.println("Queues channels (" + qChs.size() + "):");
qChs.forEach(ch -> System.out.println(" " + ch.getName()));
}
// List Commands and Queries channels
try (CQClient cq = CQClient.builder().address(ADDRESS).clientId(CLIENT_ID + "-cq").build()) {
List<CQChannel> cmds = cq.listCommandsChannels("java-");
System.out.println("Commands channels (" + cmds.size() + "):");
cmds.forEach(ch -> System.out.println(" " + ch.getName()));
List<CQChannel> queries = cq.listQueriesChannels("java-");
System.out.println("Queries channels (" + queries.size() + "):");
queries.forEach(ch -> System.out.println(" " + ch.getName()));
}
}
}
How It Works
listEventsChannels("java-")accepts a search prefix; the broker returns all channels whose names start with that string, making it easy to filter by SDK or environment.- Each channel type has its own list method:
listEventsChannels,listEventsStoreChannels,listQueuesChannels,listCommandsChannels, andlistQueriesChannels; they return typed channel objects (PubSubChannel,QueuesChannel,CQChannel). - Channel metadata on each object includes
getName(), active subscriber count, and last activity timestamp — useful for monitoring and cleanup automation. - An empty prefix (
"") lists all channels of that type across the broker.
Related
Was this page helpful?