feat(rabbitmq): add message queue management support
This commit is contained in:
1 parent
503d6748d4
commit
39e554369f
76 files changed
+14915
-707
No files matched your search
+152
-1
@@ -1,6 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import { defaultMqCapabilitiesForSystemKind, normalizeMqTabForSystemKind, resolveAvailableMqTabs, resolveInitialMqTab, resolveMqSystemKindFromConnection } from "@/lib/mq/mqConsoleDefaults";
|
||||
import {
|
||||
defaultMqCapabilitiesForSystemKind,
|
||||
isAllVhostsNamespace,
|
||||
normalizeMqTabForSystemKind,
|
||||
RABBITMQ_ALL_VHOSTS,
|
||||
resolveAvailableMqTabs,
|
||||
resolveInitialMqTab,
|
||||
resolveMqRowNamespace,
|
||||
resolveMqSystemKindFromConnection,
|
||||
resolveRabbitMqDefaultVhost,
|
||||
resolveRabbitMqSendNamespace,
|
||||
} from "@/lib/mq/mqConsoleDefaults";
|
||||
|
||||
describe("mqConsoleDefaults", () => {
|
||||
it("resolves RocketMQ from driver profile before cluster info loads", () => {
|
||||
@@ -34,4 +45,144 @@ describe("mqConsoleDefaults", () => {
|
||||
const caps = defaultMqCapabilitiesForSystemKind("rocketmq");
|
||||
expect(resolveAvailableMqTabs({ systemKind: "rocketmq", capabilities: caps })).toEqual(["broker", "topics", "subscriptions", "producers", "messages", "trace", "permissions"]);
|
||||
});
|
||||
|
||||
it("resolves RabbitMQ from driver profile and external config", () => {
|
||||
const config = {
|
||||
id: "mq-2",
|
||||
db_type: "mq",
|
||||
driver_profile: "rabbitmq",
|
||||
external_config: { systemKind: "rabbitmq", adminUrl: "", auth: { kind: "none" } },
|
||||
} as ConnectionConfig;
|
||||
|
||||
expect(resolveMqSystemKindFromConnection(config)).toBe("rabbitmq");
|
||||
expect(resolveMqSystemKindFromConnection({ ...config, external_config: undefined })).toBe("rabbitmq");
|
||||
});
|
||||
|
||||
it("treats RabbitMQ as a flat MQ system with vhost namespaces", () => {
|
||||
const caps = defaultMqCapabilitiesForSystemKind("rabbitmq");
|
||||
expect(caps.supportsTenants).toBe(false);
|
||||
expect(caps.supportsNamespaces).toBe(true);
|
||||
expect(caps.supportsPartitionedTopics).toBe(false);
|
||||
expect(caps.supportsClearBacklog).toBe(true);
|
||||
expect(caps.supportsSubscriptions).toBe(true);
|
||||
expect(caps.supportsPeekMessages).toBe(true);
|
||||
expect(caps.supportsSendMessage).toBe(true);
|
||||
expect(resolveInitialMqTab({ systemKind: "rabbitmq", initialTenant: "_flat_mq" })).toBe("topics");
|
||||
});
|
||||
|
||||
it("enables client connection management for RabbitMQ only", () => {
|
||||
expect(defaultMqCapabilitiesForSystemKind("rabbitmq").supportsClientConnections).toBe(true);
|
||||
expect(defaultMqCapabilitiesForSystemKind("kafka").supportsClientConnections).toBe(false);
|
||||
expect(defaultMqCapabilitiesForSystemKind("rocketmq").supportsClientConnections).toBe(false);
|
||||
expect(defaultMqCapabilitiesForSystemKind("pulsar").supportsClientConnections).toBeFalsy();
|
||||
});
|
||||
|
||||
it("exposes the namespaces tab for RabbitMQ vhost management", () => {
|
||||
const caps = defaultMqCapabilitiesForSystemKind("rabbitmq");
|
||||
expect(resolveAvailableMqTabs({ systemKind: "rabbitmq", capabilities: caps })).toEqual(["namespaces", "topics", "subscriptions", "monitoring", "clients", "messages", "broker", "policies", "permissions"]);
|
||||
});
|
||||
|
||||
it("enables policies & cluster monitoring for RabbitMQ only", () => {
|
||||
expect(defaultMqCapabilitiesForSystemKind("rabbitmq").supportsPolicies).toBe(true);
|
||||
expect(defaultMqCapabilitiesForSystemKind("rabbitmq").supportsClusterMonitoring).toBe(true);
|
||||
expect(defaultMqCapabilitiesForSystemKind("kafka").supportsPolicies).toBeFalsy();
|
||||
expect(defaultMqCapabilitiesForSystemKind("kafka").supportsClusterMonitoring).toBeFalsy();
|
||||
expect(defaultMqCapabilitiesForSystemKind("rocketmq").supportsPolicies).toBeFalsy();
|
||||
expect(defaultMqCapabilitiesForSystemKind("pulsar").supportsPolicies).toBeFalsy();
|
||||
});
|
||||
|
||||
it("lights the policies tab via supportsPolicies for RabbitMQ", () => {
|
||||
const caps = defaultMqCapabilitiesForSystemKind("rabbitmq");
|
||||
expect(caps.supportsRateLimits).toBe(false);
|
||||
expect(caps.supportsBacklogQuota).toBe(false);
|
||||
expect(caps.supportsRetention).toBe(false);
|
||||
|
||||
// The tab appears even when Pulsar-style rates/quotas are unsupported.
|
||||
const rabbitTabs = resolveAvailableMqTabs({ systemKind: "rabbitmq", capabilities: { ...caps, supportsPolicies: true } });
|
||||
expect(rabbitTabs).toContain("policies");
|
||||
|
||||
// Without any policy capability the tab stays hidden.
|
||||
const noPolicyCaps = { ...defaultMqCapabilitiesForSystemKind("kafka"), supportsRetention: false, supportsPolicies: false };
|
||||
expect(resolveAvailableMqTabs({ systemKind: "kafka", capabilities: noPolicyCaps })).not.toContain("policies");
|
||||
});
|
||||
|
||||
it("lights the permissions tab via supportsUserPermissions for RabbitMQ", () => {
|
||||
const caps = defaultMqCapabilitiesForSystemKind("rabbitmq");
|
||||
expect(caps.supportsPermissions).toBe(false);
|
||||
expect(caps.supportsUserPermissions).toBe(true);
|
||||
expect(defaultMqCapabilitiesForSystemKind("kafka").supportsUserPermissions).toBeFalsy();
|
||||
expect(defaultMqCapabilitiesForSystemKind("pulsar").supportsUserPermissions).toBeFalsy();
|
||||
|
||||
// The tab appears even when role-grant permissions are unsupported.
|
||||
const rabbitTabs = resolveAvailableMqTabs({ systemKind: "rabbitmq", capabilities: { ...caps, supportsPermissions: false, supportsUserPermissions: true } });
|
||||
expect(rabbitTabs).toContain("permissions");
|
||||
|
||||
// Without either capability the tab stays hidden.
|
||||
const noPermCaps = { ...defaultMqCapabilitiesForSystemKind("kafka"), supportsPermissions: false, supportsUserPermissions: false };
|
||||
expect(resolveAvailableMqTabs({ systemKind: "kafka", capabilities: noPermCaps })).not.toContain("permissions");
|
||||
});
|
||||
|
||||
it("resolves the RabbitMQ default vhost from the connection config", () => {
|
||||
expect(resolveRabbitMqDefaultVhost(undefined)).toBe("/");
|
||||
expect(resolveRabbitMqDefaultVhost({ id: "mq-3", db_type: "mq" } as ConnectionConfig)).toBe("/");
|
||||
const config = {
|
||||
id: "mq-3",
|
||||
db_type: "mq",
|
||||
driver_profile: "rabbitmq",
|
||||
external_config: { systemKind: "rabbitmq", adminUrl: "", auth: { kind: "none" }, extra: { virtualHost: "orders" } },
|
||||
} as ConnectionConfig;
|
||||
expect(resolveRabbitMqDefaultVhost(config)).toBe("orders");
|
||||
const snakeCase = {
|
||||
...config,
|
||||
external_config: { systemKind: "rabbitmq", adminUrl: "", auth: { kind: "none" }, extra: { virtual_host: "billing" } },
|
||||
} as ConnectionConfig;
|
||||
expect(resolveRabbitMqDefaultVhost(snakeCase)).toBe("billing");
|
||||
});
|
||||
|
||||
it('marks the all-vhosts selection with the "*" namespace', () => {
|
||||
expect(RABBITMQ_ALL_VHOSTS).toBe("*");
|
||||
expect(isAllVhostsNamespace("*")).toBe(true);
|
||||
expect(isAllVhostsNamespace("/")).toBe(false);
|
||||
expect(isAllVhostsNamespace("orders")).toBe(false);
|
||||
expect(isAllVhostsNamespace(undefined)).toBe(false);
|
||||
expect(isAllVhostsNamespace(null)).toBe(false);
|
||||
});
|
||||
|
||||
it("routes row-level operations to the row vhost with selection fallback", () => {
|
||||
expect(resolveMqRowNamespace({ namespace: "orders" }, "*")).toBe("orders");
|
||||
expect(resolveMqRowNamespace({ namespace: "orders" }, "/")).toBe("orders");
|
||||
expect(resolveMqRowNamespace({}, "/")).toBe("/");
|
||||
expect(resolveMqRowNamespace(undefined, "/")).toBe("/");
|
||||
expect(resolveMqRowNamespace(undefined, undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("never falls back to the all-vhosts sentinel for row-level operations", () => {
|
||||
// "*" is a listing sentinel: a row without its own vhost must not resolve
|
||||
// to it, otherwise a write would fan out across every vhost.
|
||||
expect(resolveMqRowNamespace({}, "*")).toBeUndefined();
|
||||
expect(resolveMqRowNamespace(undefined, "*")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("publishes to the row vhost or the connection default in all-vhosts mode", () => {
|
||||
// A topic entered from a cross-vhost row keeps its own vhost.
|
||||
expect(resolveRabbitMqSendNamespace({ namespace: "orders" }, "*")).toBe("orders");
|
||||
expect(resolveRabbitMqSendNamespace({ namespace: "orders" }, "/")).toBe("orders");
|
||||
// All-vhosts mode without a row topic falls back to the connection default vhost.
|
||||
expect(resolveRabbitMqSendNamespace(undefined, "*")).toBeUndefined();
|
||||
expect(resolveRabbitMqSendNamespace({}, "*")).toBeUndefined();
|
||||
// Single-vhost mode keeps the selected namespace.
|
||||
expect(resolveRabbitMqSendNamespace(undefined, "/")).toBe("/");
|
||||
});
|
||||
|
||||
it("prefers the datalist row vhost, then the fallback topic, when publishing", () => {
|
||||
// The datalist row (picked/typed topic) wins over the panel's topic prop.
|
||||
expect(resolveRabbitMqSendNamespace({ namespace: "orders" }, "*", { namespace: "billing" })).toBe("orders");
|
||||
// Without a datalist row the fallback topic's vhost is used, even in all-vhosts mode.
|
||||
expect(resolveRabbitMqSendNamespace(undefined, "*", { namespace: "billing" })).toBe("billing");
|
||||
expect(resolveRabbitMqSendNamespace({}, "*", { namespace: "billing" })).toBe("billing");
|
||||
// The fallback topic also wins over a single-vhost selection.
|
||||
expect(resolveRabbitMqSendNamespace(undefined, "/", { namespace: "billing" })).toBe("billing");
|
||||
// Nothing to go on in all-vhosts mode: fall back to the connection default vhost.
|
||||
expect(resolveRabbitMqSendNamespace(undefined, "*", undefined)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { defaultMqCapabilitiesForSystemKind } from "@/lib/mq/mqConsoleDefaults";
|
||||
import { isBuiltinRabbitMqExchange, rabbitMqExchangeDisplayName, RABBITMQ_EXCHANGE_TYPES } from "@/lib/mq/rabbitmqExchanges";
|
||||
import type { MqExchangeInfo } from "@/types/mq";
|
||||
|
||||
function exchange(partial: Partial<MqExchangeInfo>): MqExchangeInfo {
|
||||
return { name: "", type: "direct", durable: true, autoDelete: false, internal: false, ...partial };
|
||||
}
|
||||
|
||||
describe("rabbitmqExchanges", () => {
|
||||
it("offers the four creatable exchange types", () => {
|
||||
expect(RABBITMQ_EXCHANGE_TYPES).toEqual(["direct", "fanout", "topic", "headers"]);
|
||||
});
|
||||
|
||||
it("renders the default exchange with a display name", () => {
|
||||
expect(rabbitMqExchangeDisplayName(exchange({ name: "" }))).toBe("(AMQP default)");
|
||||
expect(rabbitMqExchangeDisplayName(exchange({ name: "dbx-events" }))).toBe("dbx-events");
|
||||
expect(rabbitMqExchangeDisplayName({ name: "amq.topic" })).toBe("amq.topic");
|
||||
});
|
||||
|
||||
it("marks the default and amq.* exchanges as built-in", () => {
|
||||
expect(isBuiltinRabbitMqExchange(exchange({ name: "" }))).toBe(true);
|
||||
expect(isBuiltinRabbitMqExchange(exchange({ name: "amq.direct" }))).toBe(true);
|
||||
expect(isBuiltinRabbitMqExchange(exchange({ name: "amq.headers", type: "headers" }))).toBe(true);
|
||||
expect(isBuiltinRabbitMqExchange(exchange({ name: "dbx-internal", internal: true }))).toBe(true);
|
||||
expect(isBuiltinRabbitMqExchange(exchange({ name: "dbx-events" }))).toBe(false);
|
||||
expect(isBuiltinRabbitMqExchange(exchange({ name: "amqp.custom" }))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mqConsoleDefaults RabbitMQ exchanges capability", () => {
|
||||
it("enables exchange management for RabbitMQ only", () => {
|
||||
expect(defaultMqCapabilitiesForSystemKind("rabbitmq").supportsExchanges).toBe(true);
|
||||
expect(defaultMqCapabilitiesForSystemKind("kafka").supportsExchanges).toBe(false);
|
||||
expect(defaultMqCapabilitiesForSystemKind("rocketmq").supportsExchanges).toBe(false);
|
||||
expect(defaultMqCapabilitiesForSystemKind("pulsar").supportsExchanges).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@@ -23,6 +23,8 @@ const FLAT_MQ_BASE_CAPABILITIES: MqCapabilities = {
|
||||
supportsMessageQuery: false,
|
||||
supportsDlq: false,
|
||||
supportsMessageTrace: false,
|
||||
supportsExchanges: false,
|
||||
supportsClientConnections: false,
|
||||
};
|
||||
|
||||
const PULSAR_DEFAULT_CAPABILITIES: MqCapabilities = {
|
||||
@@ -52,17 +54,17 @@ const PULSAR_DEFAULT_CAPABILITIES: MqCapabilities = {
|
||||
export function resolveMqSystemKindFromConnection(config: ConnectionConfig | undefined): MqSystemKind | undefined {
|
||||
if (!config || config.db_type !== "mq") return undefined;
|
||||
const external = config.external_config as Partial<MqAdminConfig> | undefined;
|
||||
if (external?.systemKind === "kafka" || external?.systemKind === "rocketmq" || external?.systemKind === "pulsar") {
|
||||
if (external?.systemKind === "kafka" || external?.systemKind === "rocketmq" || external?.systemKind === "rabbitmq" || external?.systemKind === "pulsar") {
|
||||
return external.systemKind;
|
||||
}
|
||||
if (config.driver_profile === "kafka" || config.driver_profile === "rocketmq" || config.driver_profile === "pulsar") {
|
||||
if (config.driver_profile === "kafka" || config.driver_profile === "rocketmq" || config.driver_profile === "rabbitmq" || config.driver_profile === "pulsar") {
|
||||
return config.driver_profile;
|
||||
}
|
||||
return "pulsar";
|
||||
}
|
||||
|
||||
export function isFlatMqSystemKind(kind: MqSystemKind | undefined): boolean {
|
||||
return kind === "kafka" || kind === "rocketmq";
|
||||
return kind === "kafka" || kind === "rocketmq" || kind === "rabbitmq";
|
||||
}
|
||||
|
||||
export function defaultMqCapabilitiesForSystemKind(kind: MqSystemKind | undefined): MqCapabilities {
|
||||
@@ -81,9 +83,81 @@ export function defaultMqCapabilitiesForSystemKind(kind: MqSystemKind | undefine
|
||||
supportsMessageTrace: true,
|
||||
};
|
||||
}
|
||||
if (kind === "rabbitmq") {
|
||||
return {
|
||||
...FLAT_MQ_BASE_CAPABILITIES,
|
||||
// RabbitMQ is an intermediate form between flat and tenant/namespace systems:
|
||||
// namespaces map to virtual hosts (list/create/delete via the management API),
|
||||
// and clearing the backlog purges the selected queue.
|
||||
supportsNamespaces: true,
|
||||
supportsPartitionedTopics: false,
|
||||
supportsResetCursor: false,
|
||||
supportsPermissions: false,
|
||||
// RabbitMQ manages exchanges & bindings on top of queues.
|
||||
supportsExchanges: true,
|
||||
// Client connections / channels come from the management API.
|
||||
supportsClientConnections: true,
|
||||
// Users & per-vhost permission triples come from the management API.
|
||||
supportsUserPermissions: true,
|
||||
// Virtual-host policies come from the management API.
|
||||
supportsPolicies: true,
|
||||
// Cluster overview & node stats come from the management API.
|
||||
supportsClusterMonitoring: true,
|
||||
};
|
||||
}
|
||||
return { ...PULSAR_DEFAULT_CAPABILITIES };
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthetic tenant used for RabbitMQ connections. RabbitMQ has no tenant
|
||||
* concept; the console pins the tenant to this value and exposes virtual
|
||||
* hosts as namespaces instead.
|
||||
*/
|
||||
export const RABBITMQ_MQ_TENANT = "_rabbitmq";
|
||||
|
||||
/**
|
||||
* Marker namespace meaning "all virtual hosts" for RabbitMQ. The backend
|
||||
* translates it into a vhost-less management API listing where every item
|
||||
* carries its own vhost.
|
||||
*/
|
||||
export const RABBITMQ_ALL_VHOSTS = "*";
|
||||
|
||||
export function isAllVhostsNamespace(namespace: string | undefined | null): boolean {
|
||||
return namespace === RABBITMQ_ALL_VHOSTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the namespace for a row-level operation: prefer the namespace the
|
||||
* row itself carries (cross-vhost listings), falling back to the currently
|
||||
* selected namespace. In "all vhosts" mode a row without its own namespace
|
||||
* resolves to undefined — "*" is a listing sentinel and must never reach a
|
||||
* write operation.
|
||||
*/
|
||||
export function resolveMqRowNamespace(row: { namespace?: string } | undefined, selectedNamespace: string | undefined): string | undefined {
|
||||
if (row?.namespace) return row.namespace;
|
||||
return isAllVhostsNamespace(selectedNamespace) ? undefined : selectedNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the virtual host a RabbitMQ publish targets. A topic chosen from a
|
||||
* row keeps its own vhost, then the fallback topic (e.g. the panel's selected
|
||||
* topic prop); in all-vhosts mode without a row topic the publish falls back
|
||||
* to the connection default vhost (no explicit namespace).
|
||||
*/
|
||||
export function resolveRabbitMqSendNamespace(topic: { namespace?: string } | undefined, selectedNamespace: string | undefined, fallbackTopic?: { namespace?: string }): string | undefined {
|
||||
const namespace = topic?.namespace || fallbackTopic?.namespace;
|
||||
if (namespace) return namespace;
|
||||
return isAllVhostsNamespace(selectedNamespace) ? undefined : selectedNamespace;
|
||||
}
|
||||
|
||||
/** Resolve the connection's default virtual host, used as the initial namespace. */
|
||||
export function resolveRabbitMqDefaultVhost(config: ConnectionConfig | undefined): string {
|
||||
const external = config?.external_config as Partial<MqAdminConfig> | undefined;
|
||||
const extra = external?.extra as Record<string, unknown> | undefined;
|
||||
const vhost = extra?.virtualHost ?? extra?.virtual_host;
|
||||
return typeof vhost === "string" && vhost.trim() ? vhost.trim() : "/";
|
||||
}
|
||||
|
||||
export type MqTab = "tenants" | "namespaces" | "topics" | "subscriptions" | "monitoring" | "clients" | "producers" | "policies" | "permissions" | "messages" | "raw" | "broker" | "dlq" | "trace";
|
||||
|
||||
export function resolveAvailableMqTabs(options: { systemKind?: MqSystemKind; capabilities: MqCapabilities }): MqTab[] {
|
||||
@@ -105,10 +179,12 @@ export function resolveAvailableMqTabs(options: { systemKind?: MqSystemKind; cap
|
||||
tabs.push("clients");
|
||||
if (capabilities.supportsSendMessage) tabs.push("messages");
|
||||
tabs.push("broker");
|
||||
if (capabilities.supportsRateLimits || capabilities.supportsBacklogQuota || capabilities.supportsRetention) {
|
||||
// RabbitMQ lights this tab via virtual-host policies instead of Pulsar rates/quotas.
|
||||
if (capabilities.supportsRateLimits || capabilities.supportsBacklogQuota || capabilities.supportsRetention || capabilities.supportsPolicies) {
|
||||
tabs.push("policies");
|
||||
}
|
||||
if (capabilities.supportsPermissions) tabs.push("permissions");
|
||||
// RabbitMQ lights this tab via user/vhost permissions instead of role grants.
|
||||
if (capabilities.supportsPermissions || capabilities.supportsUserPermissions) tabs.push("permissions");
|
||||
if (capabilities.supportsRawAdminApi) tabs.push("raw");
|
||||
return tabs;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { MqExchangeInfo, MqExchangeType } from "@/types/mq";
|
||||
|
||||
/** Exchange types creatable through the RabbitMQ admin API. */
|
||||
export const RABBITMQ_EXCHANGE_TYPES: MqExchangeType[] = ["direct", "fanout", "topic", "headers"];
|
||||
|
||||
/**
|
||||
* The default exchange has an empty name; display it as "(AMQP default)" in
|
||||
* the list, the same way the RabbitMQ management UI does.
|
||||
*/
|
||||
export function rabbitMqExchangeDisplayName(exchange: Pick<MqExchangeInfo, "name">): string {
|
||||
return exchange.name || "(AMQP default)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Built-in exchanges (the default exchange and the amq.* set) must not be
|
||||
* deleted from the console.
|
||||
*/
|
||||
export function isBuiltinRabbitMqExchange(exchange: MqExchangeInfo): boolean {
|
||||
return exchange.name === "" || exchange.name.startsWith("amq.") || exchange.internal;
|
||||
}
|
||||
Reference in new issue
Block a user