feat(mqtt): add MQTT broker connection support
This commit is contained in:
1 parent
dff33662fc
commit
8cfe380784
125 files changed
+23056
-107
No files matched your search
@@ -2658,6 +2658,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await loadVectorCollections(connectionId);
|
||||
} else if (config.db_type === "mq") {
|
||||
await loadMqTenants(connectionId, { force: true });
|
||||
} else if (config.db_type === "mqtt") {
|
||||
await loadMqttTopics(connectionId);
|
||||
} else if (config.db_type === "nacos") {
|
||||
await loadNacosNamespaces(connectionId, { force: true });
|
||||
} else {
|
||||
@@ -3324,6 +3326,48 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMqttTopics(connectionId: string) {
|
||||
const node = findConnectionNode(connectionId);
|
||||
if (!node) return;
|
||||
|
||||
node.isLoading = true;
|
||||
try {
|
||||
await ensureConnected(connectionId);
|
||||
const { mqttGetTopicTree } = await import("@/lib/backend/api");
|
||||
const topicTree = (await mqttGetTopicTree(connectionId)) as { name: string; fullPath: string; children?: unknown[]; isLeaf: boolean };
|
||||
const topicNodes = mqttTopicTreeToSidebarNodes(connectionId, topicTree);
|
||||
// Always prepend a synthetic console entry so users can open the MQTT admin
|
||||
// even when no topics are subscribed yet.
|
||||
const consoleNode: TreeNode = {
|
||||
id: `${connectionId}:mqtt-topic:__console__`,
|
||||
label: "MQTT 控制台",
|
||||
type: "mqtt-topic" as const,
|
||||
connectionId,
|
||||
children: topicNodes.length > 0 ? topicNodes : [],
|
||||
isExpanded: topicNodes.length > 0,
|
||||
};
|
||||
setChildren(node, [consoleNode]);
|
||||
node.isExpanded = true;
|
||||
} catch (e) {
|
||||
recordMetadataLoadError(connectionId, e);
|
||||
throw e;
|
||||
} finally {
|
||||
node.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function mqttTopicTreeToSidebarNodes(connectionId: string, tree: { name: string; fullPath: string; children?: unknown[]; isLeaf: boolean }): TreeNode[] {
|
||||
const children = tree.children ?? [];
|
||||
return children.map((child: any) => ({
|
||||
id: `${connectionId}:mqtt-topic:${child.fullPath}`,
|
||||
label: child.isLeaf ? child.name : `${child.name}/`,
|
||||
type: "mqtt-topic",
|
||||
connectionId,
|
||||
children: child.children?.length > 0 ? mqttTopicTreeToSidebarNodes(connectionId, child) : [],
|
||||
isExpanded: false,
|
||||
})) as TreeNode[];
|
||||
}
|
||||
|
||||
async function loadMqTenants(connectionId: string, options?: LoadTreeOptions) {
|
||||
const node = findConnectionNode(connectionId);
|
||||
if (!node) return;
|
||||
@@ -5089,6 +5133,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await loadVectorCollections(node.connectionId);
|
||||
} else if (config?.db_type === "mq") {
|
||||
await loadMqTenants(node.connectionId, options);
|
||||
} else if (config?.db_type === "mqtt") {
|
||||
await loadMqttTopics(node.connectionId);
|
||||
} else if (config?.db_type === "nacos") {
|
||||
await loadNacosNamespaces(node.connectionId, options);
|
||||
} else {
|
||||
@@ -6863,6 +6909,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
loadEtcdRoot,
|
||||
loadZooKeeperRoot,
|
||||
loadMqTenants,
|
||||
loadMqttTopics,
|
||||
loadNacosNamespaces,
|
||||
updateRedisDbKeyStats,
|
||||
loadMongoDatabases,
|
||||
|
||||
@@ -1735,6 +1735,33 @@ export const useQueryStore = defineStore("query", () => {
|
||||
return id;
|
||||
}
|
||||
|
||||
function openMqttAdmin(connectionId: string, target?: { initialTopic?: string }) {
|
||||
const existing = tabs.value.find((tab) => tab.mode === "mqtt" && tab.connectionId === connectionId);
|
||||
if (existing) {
|
||||
if (target?.initialTopic) existing.mqttInitialTopic = target.initialTopic;
|
||||
switchTab(existing.id);
|
||||
return existing.id;
|
||||
}
|
||||
|
||||
const conn = useConnectionStore().getConfig(connectionId);
|
||||
const id = uuid();
|
||||
const tab: QueryTab = {
|
||||
id,
|
||||
title: `${conn?.name || "MQTT"} Console`,
|
||||
connectionId,
|
||||
database: conn?.database || "",
|
||||
sql: "",
|
||||
isExecuting: false,
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
mode: "mqtt",
|
||||
mqttInitialTopic: target?.initialTopic,
|
||||
};
|
||||
tabs.value.push(tab);
|
||||
activeTabId.value = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
function clearNacosNavigationTarget(connectionId: string, namespace: string, requestId?: number) {
|
||||
const tab = tabs.value.find((candidate) => candidate.mode === "nacos" && candidate.connectionId === connectionId && (candidate.nacosNamespace || "") === namespace);
|
||||
if (!tab || (requestId !== undefined && tab.nacosTargetRequestId !== requestId)) return;
|
||||
@@ -5312,6 +5339,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
openNacosDashboard,
|
||||
openDamengJobAdmin,
|
||||
openMqAdmin,
|
||||
openMqttAdmin,
|
||||
openNacosAdmin,
|
||||
clearNacosNavigationTarget,
|
||||
openTableStructure,
|
||||
|
||||
Reference in new issue
Block a user