feat(rocketmq): add agent and management console
This commit is contained in:
86 files changed
+12373
-505
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_ROCKETMQ_TOPIC_TYPE_FILTERS, buildRocketMqTraceTopicOptions, isProtectedRocketMqTopic, matchesRocketMqTypeFilters, resolveRocketMqMessageType } from "@/lib/mq/rocketmqTopicTypes";
|
||||
import type { TopicInfo } from "@/types/mq";
|
||||
|
||||
function topic(partial: Partial<TopicInfo>): TopicInfo {
|
||||
return {
|
||||
name: partial.name ?? partial.shortName ?? "demo",
|
||||
shortName: partial.shortName ?? partial.name ?? "demo",
|
||||
partitioned: partial.partitioned ?? false,
|
||||
persistent: partial.persistent ?? true,
|
||||
...partial,
|
||||
};
|
||||
}
|
||||
|
||||
describe("rocketmqTopicTypes", () => {
|
||||
it("resolves dashboard-style message types", () => {
|
||||
expect(resolveRocketMqMessageType(topic({ messageType: "NORMAL" }))).toBe("NORMAL");
|
||||
expect(resolveRocketMqMessageType(topic({ messageType: "DELAY" }))).toBe("DELAY");
|
||||
expect(resolveRocketMqMessageType(topic({ messageType: "ORDER" }))).toBe("FIFO");
|
||||
expect(resolveRocketMqMessageType(topic({ messageType: "RETRY" }))).toBe("RETRY");
|
||||
expect(resolveRocketMqMessageType(topic({ internal: true }))).toBe("SYSTEM");
|
||||
expect(resolveRocketMqMessageType(topic({}))).toBe("UNSPECIFIED");
|
||||
});
|
||||
|
||||
it("filters topics by selected message types", () => {
|
||||
const filters = { ...DEFAULT_ROCKETMQ_TOPIC_TYPE_FILTERS };
|
||||
expect(matchesRocketMqTypeFilters(topic({ messageType: "NORMAL" }), filters)).toBe(true);
|
||||
expect(matchesRocketMqTypeFilters(topic({ messageType: "SYSTEM" }), filters)).toBe(false);
|
||||
filters.SYSTEM = true;
|
||||
expect(matchesRocketMqTypeFilters(topic({ messageType: "SYSTEM" }), filters)).toBe(true);
|
||||
});
|
||||
|
||||
it("marks retry, dlq and system topics as protected", () => {
|
||||
expect(isProtectedRocketMqTopic(topic({ messageType: "NORMAL" }))).toBe(false);
|
||||
expect(isProtectedRocketMqTopic(topic({ messageType: "RETRY" }))).toBe(true);
|
||||
expect(isProtectedRocketMqTopic(topic({ messageType: "DLQ" }))).toBe(true);
|
||||
expect(isProtectedRocketMqTopic(topic({ internal: true }))).toBe(true);
|
||||
});
|
||||
|
||||
it("builds trace topic options with default and trace-related topics", () => {
|
||||
expect(buildRocketMqTraceTopicOptions([])).toEqual(["RMQ_SYS_TRACE_TOPIC"]);
|
||||
expect(buildRocketMqTraceTopicOptions([topic({ shortName: "RMQ_SYS_TRACE_TOPIC", internal: true }), topic({ shortName: "MyCustomTraceTopic", messageType: "NORMAL" }), topic({ shortName: "orders", messageType: "NORMAL" })])).toEqual(["RMQ_SYS_TRACE_TOPIC", "MyCustomTraceTopic"]);
|
||||
});
|
||||
});
|
||||
@@ -428,7 +428,16 @@ export const mqListPermissions = forward("mqListPermissions");
|
||||
export const mqIssueToken = forward("mqIssueToken");
|
||||
export const mqListTokenRecords = forward("mqListTokenRecords");
|
||||
export const mqGetBacklog = forward("mqGetBacklog");
|
||||
export const mqGetConsumerGroupConfig = forward("mqGetConsumerGroupConfig");
|
||||
export const mqAlterConsumerGroupConfig = forward("mqAlterConsumerGroupConfig");
|
||||
export const mqGetClusterInfo = forward("mqGetClusterInfo");
|
||||
export const mqGetTopicRoute = forward("mqGetTopicRoute");
|
||||
export const mqAlterTopicConfig = forward("mqAlterTopicConfig");
|
||||
export const mqSkipTopicAccumulation = forward("mqSkipTopicAccumulation");
|
||||
export const mqViewMessage = forward("mqViewMessage");
|
||||
export const mqQueryMessagesByKey = forward("mqQueryMessagesByKey");
|
||||
export const mqQueryMessagesByTopic = forward("mqQueryMessagesByTopic");
|
||||
export const mqQueryMessageTrace = forward("mqQueryMessageTrace");
|
||||
export const mqRawRequest = forward("mqRawRequest");
|
||||
export const mqSendMessage = forward("mqSendMessage");
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import type {
|
||||
MqTokenRecord,
|
||||
MqIssuedToken,
|
||||
BacklogStats,
|
||||
RocketMqConsumerGroupConfig,
|
||||
PeekedMessage,
|
||||
PeekMessagesOptions,
|
||||
MqRawRequest,
|
||||
@@ -206,10 +207,46 @@ export async function mqGetBacklog(connectionId: string, topic: TopicRef, sub?:
|
||||
return post("/api/mq/monitoring/backlog", { connectionId, topic, sub });
|
||||
}
|
||||
|
||||
export async function mqGetConsumerGroupConfig(connectionId: string, groupId: string): Promise<RocketMqConsumerGroupConfig> {
|
||||
return post("/api/mq/consumers/group-config/get", { connectionId, groupId });
|
||||
}
|
||||
|
||||
export async function mqAlterConsumerGroupConfig(connectionId: string, groupId: string, config: Partial<RocketMqConsumerGroupConfig>): Promise<void> {
|
||||
return post("/api/mq/consumers/group-config/alter", { connectionId, groupId, config });
|
||||
}
|
||||
|
||||
export async function mqGetClusterInfo(connectionId: string): Promise<ClusterInfo> {
|
||||
return post("/api/mq/monitoring/cluster-info", { connectionId });
|
||||
}
|
||||
|
||||
export async function mqGetTopicRoute(connectionId: string, topic: TopicRef): Promise<unknown> {
|
||||
return post("/api/mq/topics/route", { connectionId, topic });
|
||||
}
|
||||
|
||||
export async function mqAlterTopicConfig(connectionId: string, topic: TopicRef, configs: unknown): Promise<void> {
|
||||
return post("/api/mq/topics/alter-config", { connectionId, topic, configs });
|
||||
}
|
||||
|
||||
export async function mqSkipTopicAccumulation(connectionId: string, topic: TopicRef): Promise<unknown> {
|
||||
return post("/api/mq/topics/skip-accumulation", { connectionId, topic });
|
||||
}
|
||||
|
||||
export async function mqViewMessage(connectionId: string, topic: TopicRef, msgId: string): Promise<unknown> {
|
||||
return post("/api/mq/messages/view", { connectionId, topic, msgId });
|
||||
}
|
||||
|
||||
export async function mqQueryMessagesByKey(connectionId: string, topic: TopicRef, key: string, begin: number, end: number, maxNum: number): Promise<unknown> {
|
||||
return post("/api/mq/messages/query-by-key", { connectionId, topic, key, begin, end, maxNum });
|
||||
}
|
||||
|
||||
export async function mqQueryMessagesByTopic(connectionId: string, topic: TopicRef, begin: number, end: number, maxNum: number): Promise<unknown> {
|
||||
return post("/api/mq/messages/query-by-topic", { connectionId, topic, begin, end, maxNum });
|
||||
}
|
||||
|
||||
export async function mqQueryMessageTrace(connectionId: string, msgId: string, traceTopic?: string): Promise<unknown> {
|
||||
return post("/api/mq/messages/trace", { connectionId, msgId, traceTopic });
|
||||
}
|
||||
|
||||
export async function mqRawRequest(connectionId: string, req: MqRawRequest): Promise<MqRawResponse> {
|
||||
return post("/api/mq/raw", { connectionId, req });
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import type {
|
||||
MqTokenRecord,
|
||||
MqIssuedToken,
|
||||
BacklogStats,
|
||||
RocketMqConsumerGroupConfig,
|
||||
PeekedMessage,
|
||||
PeekMessagesOptions,
|
||||
MqRawRequest,
|
||||
@@ -202,10 +203,46 @@ export async function mqGetBacklog(connectionId: string, topic: TopicRef, sub?:
|
||||
return invoke("mq_get_backlog", { connectionId, topic, sub });
|
||||
}
|
||||
|
||||
export async function mqGetConsumerGroupConfig(connectionId: string, groupId: string): Promise<RocketMqConsumerGroupConfig> {
|
||||
return invoke("mq_get_consumer_group_config", { connectionId, groupId });
|
||||
}
|
||||
|
||||
export async function mqAlterConsumerGroupConfig(connectionId: string, groupId: string, config: Partial<RocketMqConsumerGroupConfig>): Promise<void> {
|
||||
return invoke("mq_alter_consumer_group_config", { connectionId, groupId, config });
|
||||
}
|
||||
|
||||
export async function mqGetClusterInfo(connectionId: string): Promise<ClusterInfo> {
|
||||
return invoke("mq_get_cluster_info", { connectionId });
|
||||
}
|
||||
|
||||
export async function mqGetTopicRoute(connectionId: string, topic: TopicRef): Promise<unknown> {
|
||||
return invoke("mq_get_topic_route", { connectionId, topic });
|
||||
}
|
||||
|
||||
export async function mqAlterTopicConfig(connectionId: string, topic: TopicRef, configs: unknown): Promise<void> {
|
||||
return invoke("mq_alter_topic_config", { connectionId, topic, configs });
|
||||
}
|
||||
|
||||
export async function mqSkipTopicAccumulation(connectionId: string, topic: TopicRef): Promise<unknown> {
|
||||
return invoke("mq_skip_topic_accumulation", { connectionId, topic });
|
||||
}
|
||||
|
||||
export async function mqViewMessage(connectionId: string, topic: TopicRef, msgId: string): Promise<unknown> {
|
||||
return invoke("mq_view_message", { connectionId, topic, msgId });
|
||||
}
|
||||
|
||||
export async function mqQueryMessagesByKey(connectionId: string, topic: TopicRef, key: string, begin: number, end: number, maxNum: number): Promise<unknown> {
|
||||
return invoke("mq_query_messages_by_key", { connectionId, topic, key, begin, end, maxNum });
|
||||
}
|
||||
|
||||
export async function mqQueryMessagesByTopic(connectionId: string, topic: TopicRef, begin: number, end: number, maxNum: number): Promise<unknown> {
|
||||
return invoke("mq_query_messages_by_topic", { connectionId, topic, begin, end, maxNum });
|
||||
}
|
||||
|
||||
export async function mqQueryMessageTrace(connectionId: string, msgId: string, traceTopic?: string): Promise<unknown> {
|
||||
return invoke("mq_query_message_trace", { connectionId, msgId, traceTopic });
|
||||
}
|
||||
|
||||
// Raw request
|
||||
export async function mqRawRequest(connectionId: string, req: MqRawRequest): Promise<MqRawResponse> {
|
||||
return invoke("mq_raw_request", { connectionId, req });
|
||||
|
||||
@@ -14,6 +14,10 @@ describe("driverStoreFocusForInstallError", () => {
|
||||
target: "driver",
|
||||
driver: "kafka",
|
||||
});
|
||||
expect(driverStoreFocusForInstallError("rocketmq driver is not installed. Please install it from the Driver Manager.", "mq", "rocketmq")).toEqual({
|
||||
target: "driver",
|
||||
driver: "rocketmq",
|
||||
});
|
||||
});
|
||||
|
||||
it("focuses the JRE section for missing JRE errors", () => {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { detectMqUiAuthKind, isMqAuthKindAllowedForSystem } from "@/lib/connection/mqAuth";
|
||||
|
||||
describe("mqAuth", () => {
|
||||
it("allows basic auth for RocketMQ", () => {
|
||||
expect(isMqAuthKindAllowedForSystem("rocketmq", "basic")).toBe(true);
|
||||
expect(isMqAuthKindAllowedForSystem("rocketmq", "kerberos")).toBe(false);
|
||||
});
|
||||
|
||||
it("detects RocketMQ basic auth from config", () => {
|
||||
expect(
|
||||
detectMqUiAuthKind({
|
||||
systemKind: "rocketmq",
|
||||
authKind: "basic",
|
||||
saslMechanism: "",
|
||||
jaasConfig: "",
|
||||
}),
|
||||
).toBe("basic");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { normalizeRocketmqNamesrvAddr } from "@/lib/connection/rocketmqNamesrv";
|
||||
|
||||
describe("normalizeRocketmqNamesrvAddr", () => {
|
||||
it("normalizes a single host:port address", () => {
|
||||
expect(normalizeRocketmqNamesrvAddr("127.0.0.1:9876")).toBe("127.0.0.1:9876");
|
||||
});
|
||||
|
||||
it("joins multiple addresses separated by commas", () => {
|
||||
expect(normalizeRocketmqNamesrvAddr("127.0.0.1:9876, 192.168.1.2:9876")).toBe("127.0.0.1:9876;192.168.1.2:9876");
|
||||
});
|
||||
|
||||
it("rejects empty input", () => {
|
||||
expect(() => normalizeRocketmqNamesrvAddr(" ")).toThrow(/required/i);
|
||||
});
|
||||
|
||||
it("rejects URL schemes", () => {
|
||||
expect(() => normalizeRocketmqNamesrvAddr("http://127.0.0.1:9876")).toThrow(/without a URL scheme/i);
|
||||
});
|
||||
});
|
||||
@@ -12,7 +12,11 @@ export function agentDriverInstallKey(dbType: DatabaseType | undefined, driverPr
|
||||
if (dbType === "mongodb") return "mongodb";
|
||||
if (dbType === "dameng") return "dameng";
|
||||
if (dbType === "gbase") return driverProfile === "gbase8s" ? "gbase8s" : "gbase8a";
|
||||
if (dbType === "mq") return driverProfile === "kafka" ? "kafka" : undefined;
|
||||
if (dbType === "mq") {
|
||||
if (driverProfile === "kafka") return "kafka";
|
||||
if (driverProfile === "rocketmq") return "rocketmq";
|
||||
return undefined;
|
||||
}
|
||||
return driverProfile && driverProfile !== dbType ? driverProfile : dbType;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@ export type MqAuthKind = MqAuth["kind"];
|
||||
export type MqUiAuthKind = MqAuthKind | "kerberos";
|
||||
|
||||
const KAFKA_AUTH_KINDS = new Set<MqUiAuthKind>(["none", "basic", "kerberos"]);
|
||||
const ROCKETMQ_AUTH_KINDS = new Set<MqUiAuthKind>(["none", "basic"]);
|
||||
|
||||
export function isMqAuthKindAllowedForSystem(systemKind: MqSystemKind, authKind: MqUiAuthKind): boolean {
|
||||
if (systemKind === "kafka") return KAFKA_AUTH_KINDS.has(authKind);
|
||||
if (systemKind === "rocketmq") return ROCKETMQ_AUTH_KINDS.has(authKind);
|
||||
return authKind !== "kerberos";
|
||||
}
|
||||
|
||||
@@ -17,6 +19,9 @@ export function detectMqUiAuthKind({ systemKind, authKind, saslMechanism, jaasCo
|
||||
}
|
||||
return authKind === "basic" ? "basic" : "none";
|
||||
}
|
||||
if (systemKind === "rocketmq") {
|
||||
return authKind === "basic" ? "basic" : "none";
|
||||
}
|
||||
|
||||
return authKind || "none";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
const ROCKETMQ_NAMESRV_SEPARATOR = /[\s,;,;]+/u;
|
||||
|
||||
function requireRocketmqNamesrv(value: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) throw new Error("RocketMQ NameServer address is required");
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function normalizeRocketmqNamesrvServer(server: string): string {
|
||||
if (server.includes("://")) {
|
||||
throw new Error("RocketMQ NameServer addresses must be host:port values without a URL scheme");
|
||||
}
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(`rocketmq://${server}`);
|
||||
} catch {
|
||||
throw new Error("RocketMQ NameServer addresses are invalid");
|
||||
}
|
||||
if (!parsed.hostname || parsed.username || parsed.password || parsed.search || parsed.hash || (parsed.pathname && parsed.pathname !== "/")) {
|
||||
throw new Error("RocketMQ NameServer addresses are invalid");
|
||||
}
|
||||
return server;
|
||||
}
|
||||
|
||||
export function normalizeRocketmqNamesrvAddr(value: string): string {
|
||||
const servers = requireRocketmqNamesrv(value)
|
||||
.split(ROCKETMQ_NAMESRV_SEPARATOR)
|
||||
.map((server) => server.trim())
|
||||
.filter(Boolean)
|
||||
.map(normalizeRocketmqNamesrvServer);
|
||||
if (!servers.length) throw new Error("RocketMQ NameServer address is required");
|
||||
return servers.join(";");
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import { defaultMqCapabilitiesForSystemKind, normalizeMqTabForSystemKind, resolveAvailableMqTabs, resolveInitialMqTab, resolveMqSystemKindFromConnection } from "@/lib/mq/mqConsoleDefaults";
|
||||
|
||||
describe("mqConsoleDefaults", () => {
|
||||
it("resolves RocketMQ from driver profile before cluster info loads", () => {
|
||||
const config = {
|
||||
id: "mq-1",
|
||||
db_type: "mq",
|
||||
driver_profile: "rocketmq",
|
||||
external_config: { systemKind: "rocketmq", adminUrl: "", auth: { kind: "none" } },
|
||||
} as ConnectionConfig;
|
||||
|
||||
expect(resolveMqSystemKindFromConnection(config)).toBe("rocketmq");
|
||||
expect(defaultMqCapabilitiesForSystemKind("rocketmq").supportsTenants).toBe(false);
|
||||
expect(defaultMqCapabilitiesForSystemKind("rocketmq").supportsNamespaces).toBe(false);
|
||||
});
|
||||
|
||||
it("opens flat MQ consoles on the topics tab", () => {
|
||||
expect(resolveInitialMqTab({ systemKind: "rocketmq", initialTenant: "_flat_mq" })).toBe("topics");
|
||||
expect(resolveInitialMqTab({ systemKind: "pulsar" })).toBe("tenants");
|
||||
expect(resolveInitialMqTab({ systemKind: "pulsar", initialTenant: "public" })).toBe("namespaces");
|
||||
});
|
||||
|
||||
it("falls back dlq tab to messages for RocketMQ", () => {
|
||||
expect(normalizeMqTabForSystemKind("dlq", "rocketmq")).toBe("messages");
|
||||
expect(normalizeMqTabForSystemKind("trace", "rocketmq")).toBe("trace");
|
||||
expect(normalizeMqTabForSystemKind("trace", "pulsar")).toBe("trace");
|
||||
expect(resolveInitialMqTab({ systemKind: "rocketmq", initialTab: "dlq" })).toBe("messages");
|
||||
expect(resolveInitialMqTab({ systemKind: "rocketmq", initialTab: "trace" })).toBe("trace");
|
||||
});
|
||||
|
||||
it("exposes RocketMQ tabs including trace but not dlq", () => {
|
||||
const caps = defaultMqCapabilitiesForSystemKind("rocketmq");
|
||||
expect(resolveAvailableMqTabs({ systemKind: "rocketmq", capabilities: caps })).toEqual(["broker", "topics", "subscriptions", "producers", "messages", "trace", "permissions"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { matchesRocketMqConsumerGroupTypeFilters, resolveRocketMqConsumerGroupMessageModel, resolveRocketMqConsumerGroupType } from "@/lib/mq/rocketmqConsumerGroupTypes";
|
||||
|
||||
describe("rocketmqConsumerGroupTypes", () => {
|
||||
it("resolves group type from consumerGroupType or subType", () => {
|
||||
expect(resolveRocketMqConsumerGroupType({ consumerGroupType: "FIFO", subType: "NORMAL" })).toBe("FIFO");
|
||||
expect(resolveRocketMqConsumerGroupType({ subType: "SYSTEM" })).toBe("SYSTEM");
|
||||
expect(resolveRocketMqConsumerGroupType({ subType: "CONSUME_PASSIVELY ? CLUSTERING" })).toBe("NORMAL");
|
||||
});
|
||||
|
||||
it("filters by dashboard group types", () => {
|
||||
const filters = { NORMAL: true, FIFO: true, SYSTEM: false };
|
||||
expect(matchesRocketMqConsumerGroupTypeFilters({ consumerGroupType: "NORMAL", subType: "NORMAL" }, filters)).toBe(true);
|
||||
expect(matchesRocketMqConsumerGroupTypeFilters({ consumerGroupType: "SYSTEM", subType: "SYSTEM" }, filters)).toBe(false);
|
||||
});
|
||||
|
||||
it("resolves message model", () => {
|
||||
expect(resolveRocketMqConsumerGroupMessageModel({ messageModel: "BROADCASTING" })).toBe("BROADCASTING");
|
||||
expect(resolveRocketMqConsumerGroupMessageModel({})).toBe("CLUSTERING");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { PeekedMessage } from "@/types/mq";
|
||||
import { rocketMqDisplayFromPeeked } from "@/lib/mq/rocketmqMessageUtils";
|
||||
|
||||
describe("rocketMqDisplayFromPeeked", () => {
|
||||
it("maps RocketMQ peek fields including msgId, tag and queue offset", () => {
|
||||
const peeked: PeekedMessage = {
|
||||
position: 1,
|
||||
messageId: "0BC16699165C03B925DB8A404E2D****",
|
||||
key: "order-1",
|
||||
publishTime: "1710000000000",
|
||||
properties: {
|
||||
partition: "2",
|
||||
offset: "15",
|
||||
tag: "cs-pt-dlq-test",
|
||||
},
|
||||
headers: {},
|
||||
payloadBase64: "",
|
||||
payloadText: "dlq message",
|
||||
};
|
||||
|
||||
expect(rocketMqDisplayFromPeeked(peeked, "%DLQ%cs-pt-test-group")).toEqual({
|
||||
messageId: "0BC16699165C03B925DB8A404E2D****",
|
||||
partition: 2,
|
||||
offset: 15,
|
||||
key: "order-1",
|
||||
tag: "cs-pt-dlq-test",
|
||||
timestamp: 1710000000000,
|
||||
payloadText: "dlq message",
|
||||
payloadBase64: "",
|
||||
headers: {},
|
||||
topic: "%DLQ%cs-pt-test-group",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to TAGS header when tag property is missing", () => {
|
||||
const peeked: PeekedMessage = {
|
||||
position: 1,
|
||||
messageId: "abc",
|
||||
properties: {},
|
||||
headers: { TAGS: "fallback-tag" },
|
||||
payloadBase64: "",
|
||||
};
|
||||
|
||||
expect(rocketMqDisplayFromPeeked(peeked).tag).toBe("fallback-tag");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatRocketMqTraceError, isRocketMqTraceTopicRouteMissingError } from "@/lib/mq/rocketmqTraceUtils";
|
||||
|
||||
describe("rocketmqTraceUtils", () => {
|
||||
it("detects RocketMQ trace topic route missing errors", () => {
|
||||
expect(isRocketMqTraceTopicRouteMissingError(new Error("Agent RPC error (-1): CODE: 17 DESC: The topic[RMQ_SYS_TRACE_TOPIC] not matched route info"))).toBe(true);
|
||||
expect(isRocketMqTraceTopicRouteMissingError(new Error("CODE: 208 DESC: no matched message"))).toBe(false);
|
||||
});
|
||||
|
||||
it("returns a friendly hint for trace topic route missing errors", () => {
|
||||
const hint = "Enable traceTopicEnable on broker";
|
||||
expect(formatRocketMqTraceError(new Error("CODE: 17 DESC: No topic route info in name server for the topic: RMQ_SYS_TRACE_TOPIC"), hint)).toBe(hint);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import type { MqAdminConfig, MqCapabilities, MqSystemKind } from "@/types/mq";
|
||||
|
||||
const FLAT_MQ_BASE_CAPABILITIES: MqCapabilities = {
|
||||
supportsTenants: false,
|
||||
supportsNamespaces: false,
|
||||
supportsPartitionedTopics: true,
|
||||
supportsSubscriptions: true,
|
||||
supportsCreateSubscription: false,
|
||||
supportsResetCursor: true,
|
||||
supportsSkipMessages: false,
|
||||
supportsClearBacklog: true,
|
||||
supportsPeekMessages: true,
|
||||
supportsExpireMessages: false,
|
||||
supportsRateLimits: false,
|
||||
supportsBacklogQuota: false,
|
||||
supportsRetention: false,
|
||||
supportsPermissions: true,
|
||||
supportsGeoReplication: false,
|
||||
supportsTokenManagement: false,
|
||||
supportsRawAdminApi: false,
|
||||
supportsSendMessage: true,
|
||||
supportsMessageQuery: false,
|
||||
supportsDlq: false,
|
||||
supportsMessageTrace: false,
|
||||
};
|
||||
|
||||
const PULSAR_DEFAULT_CAPABILITIES: MqCapabilities = {
|
||||
supportsTenants: true,
|
||||
supportsNamespaces: true,
|
||||
supportsPartitionedTopics: true,
|
||||
supportsSubscriptions: true,
|
||||
supportsCreateSubscription: true,
|
||||
supportsResetCursor: true,
|
||||
supportsSkipMessages: true,
|
||||
supportsClearBacklog: true,
|
||||
supportsPeekMessages: true,
|
||||
supportsExpireMessages: true,
|
||||
supportsRateLimits: true,
|
||||
supportsBacklogQuota: true,
|
||||
supportsRetention: true,
|
||||
supportsPermissions: true,
|
||||
supportsGeoReplication: true,
|
||||
supportsTokenManagement: true,
|
||||
supportsRawAdminApi: true,
|
||||
supportsSendMessage: false,
|
||||
supportsMessageQuery: false,
|
||||
supportsDlq: false,
|
||||
supportsMessageTrace: false,
|
||||
};
|
||||
|
||||
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") {
|
||||
return external.systemKind;
|
||||
}
|
||||
if (config.driver_profile === "kafka" || config.driver_profile === "rocketmq" || config.driver_profile === "pulsar") {
|
||||
return config.driver_profile;
|
||||
}
|
||||
return "pulsar";
|
||||
}
|
||||
|
||||
export function isFlatMqSystemKind(kind: MqSystemKind | undefined): boolean {
|
||||
return kind === "kafka" || kind === "rocketmq";
|
||||
}
|
||||
|
||||
export function defaultMqCapabilitiesForSystemKind(kind: MqSystemKind | undefined): MqCapabilities {
|
||||
if (kind === "kafka") {
|
||||
return {
|
||||
...FLAT_MQ_BASE_CAPABILITIES,
|
||||
supportsRetention: true,
|
||||
supportsRateLimits: false,
|
||||
};
|
||||
}
|
||||
if (kind === "rocketmq") {
|
||||
return {
|
||||
...FLAT_MQ_BASE_CAPABILITIES,
|
||||
supportsMessageQuery: true,
|
||||
supportsDlq: true,
|
||||
supportsMessageTrace: true,
|
||||
};
|
||||
}
|
||||
return { ...PULSAR_DEFAULT_CAPABILITIES };
|
||||
}
|
||||
|
||||
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[] {
|
||||
const { systemKind, capabilities } = options;
|
||||
if (systemKind === "rocketmq") {
|
||||
const tabs: MqTab[] = ["broker", "topics", "subscriptions", "producers"];
|
||||
if (capabilities.supportsMessageQuery || capabilities.supportsSendMessage) tabs.push("messages");
|
||||
if (capabilities.supportsMessageTrace) tabs.push("trace");
|
||||
if (capabilities.supportsPermissions) tabs.push("permissions");
|
||||
return tabs;
|
||||
}
|
||||
|
||||
const tabs: MqTab[] = [];
|
||||
if (capabilities.supportsTenants) tabs.push("tenants");
|
||||
if (capabilities.supportsNamespaces) tabs.push("namespaces");
|
||||
tabs.push("topics");
|
||||
if (capabilities.supportsSubscriptions) tabs.push("subscriptions");
|
||||
tabs.push("monitoring");
|
||||
tabs.push("clients");
|
||||
if (capabilities.supportsSendMessage) tabs.push("messages");
|
||||
tabs.push("broker");
|
||||
if (capabilities.supportsRateLimits || capabilities.supportsBacklogQuota || capabilities.supportsRetention) {
|
||||
tabs.push("policies");
|
||||
}
|
||||
if (capabilities.supportsPermissions) tabs.push("permissions");
|
||||
if (capabilities.supportsRawAdminApi) tabs.push("raw");
|
||||
return tabs;
|
||||
}
|
||||
|
||||
export function normalizeMqTabForSystemKind(tab: MqTab, systemKind?: MqSystemKind): MqTab {
|
||||
if (systemKind === "rocketmq" && tab === "dlq") {
|
||||
return "messages";
|
||||
}
|
||||
return tab;
|
||||
}
|
||||
|
||||
export function resolveInitialMqTab(options: { initialTab?: MqTab; initialTenant?: string; systemKind?: MqSystemKind }): MqTab {
|
||||
if (options.initialTab) {
|
||||
return normalizeMqTabForSystemKind(options.initialTab, options.systemKind);
|
||||
}
|
||||
if (isFlatMqSystemKind(options.systemKind)) return "topics";
|
||||
if (options.initialTenant) return "namespaces";
|
||||
return "tenants";
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { SubscriptionInfo } from "@/types/mq";
|
||||
|
||||
export type RocketMqConsumerGroupType = "NORMAL" | "FIFO" | "SYSTEM";
|
||||
|
||||
export const ROCKETMQ_CONSUMER_GROUP_TYPES: readonly RocketMqConsumerGroupType[] = ["NORMAL", "FIFO", "SYSTEM"];
|
||||
|
||||
export const DEFAULT_ROCKETMQ_CONSUMER_GROUP_TYPE_FILTERS: Record<RocketMqConsumerGroupType, boolean> = {
|
||||
NORMAL: true,
|
||||
FIFO: true,
|
||||
SYSTEM: false,
|
||||
};
|
||||
|
||||
export function resolveRocketMqConsumerGroupType(sub: Pick<SubscriptionInfo, "consumerGroupType" | "subType">): RocketMqConsumerGroupType {
|
||||
const raw = (sub.consumerGroupType ?? sub.subType)?.trim().toUpperCase();
|
||||
if (raw === "FIFO" || raw === "ORDER" || raw === "ORDERLY") return "FIFO";
|
||||
if (raw === "SYSTEM") return "SYSTEM";
|
||||
if (raw === "NORMAL") return "NORMAL";
|
||||
return "NORMAL";
|
||||
}
|
||||
|
||||
export function matchesRocketMqConsumerGroupTypeFilters(sub: Pick<SubscriptionInfo, "consumerGroupType" | "subType">, filters: Record<RocketMqConsumerGroupType, boolean>): boolean {
|
||||
return filters[resolveRocketMqConsumerGroupType(sub)] === true;
|
||||
}
|
||||
|
||||
export function resolveRocketMqConsumerGroupMessageModel(sub: Pick<SubscriptionInfo, "messageModel">): "CLUSTERING" | "BROADCASTING" {
|
||||
return sub.messageModel?.trim().toUpperCase() === "BROADCASTING" ? "BROADCASTING" : "CLUSTERING";
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import type { PeekedMessage } from "@/types/mq";
|
||||
|
||||
function peekedPropertyNumber(properties: Record<string, string>, key: string): number | undefined {
|
||||
const raw = properties[key]?.trim();
|
||||
if (!raw) return undefined;
|
||||
const parsed = Number(raw);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
export interface RocketMqDisplayMessage {
|
||||
messageId?: string;
|
||||
partition?: number;
|
||||
offset?: number;
|
||||
key?: string;
|
||||
tag?: string;
|
||||
timestamp?: number;
|
||||
payloadText?: string;
|
||||
payloadBase64?: string;
|
||||
headers?: Record<string, string>;
|
||||
topic?: string;
|
||||
}
|
||||
|
||||
function objectRecord(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
|
||||
}
|
||||
|
||||
function stringField(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value.trim() ? value : undefined;
|
||||
}
|
||||
|
||||
function numberField(value: unknown): number | undefined {
|
||||
if (typeof value === "number" && Number.isFinite(value)) return value;
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseMessageRow(value: unknown): RocketMqDisplayMessage | undefined {
|
||||
const body = objectRecord(value);
|
||||
if (!Object.keys(body).length) return undefined;
|
||||
const headers = objectRecord(body.headers);
|
||||
const headerMap: Record<string, string> = {};
|
||||
for (const [key, val] of Object.entries(headers)) {
|
||||
headerMap[key] = typeof val === "string" ? val : String(val ?? "");
|
||||
}
|
||||
return {
|
||||
topic: stringField(body.topic),
|
||||
messageId: stringField(body.messageId) ?? stringField(body.msgId),
|
||||
partition: numberField(body.partition) ?? numberField(body.queueId),
|
||||
offset: numberField(body.offset) ?? numberField(body.queueOffset),
|
||||
key: stringField(body.key) ?? stringField(body.keys),
|
||||
tag: stringField(body.tag) ?? stringField(body.tags),
|
||||
timestamp: numberField(body.timestamp) ?? numberField(body.storeTimestamp),
|
||||
payloadText: stringField(body.payloadText),
|
||||
payloadBase64: stringField(body.payloadBase64),
|
||||
headers: headerMap,
|
||||
};
|
||||
}
|
||||
|
||||
/** Parse messages from mqViewMessage / mqQueryMessagesByKey / mqQueryMessagesByTopic / mqQueryMessageTrace responses. */
|
||||
export function parseRocketMqMessagesFromResult(result: unknown): RocketMqDisplayMessage[] {
|
||||
const root = objectRecord(result);
|
||||
const single = root.message ?? root.msg;
|
||||
if (single) {
|
||||
const parsed = parseMessageRow(single);
|
||||
return parsed ? [parsed] : [];
|
||||
}
|
||||
const list = root.messages;
|
||||
if (!Array.isArray(list)) return [];
|
||||
return list.map(parseMessageRow).filter((item): item is RocketMqDisplayMessage => !!item);
|
||||
}
|
||||
|
||||
export function rocketMqMessagePayload(message: RocketMqDisplayMessage): string {
|
||||
if (message.payloadText) return message.payloadText;
|
||||
if (message.payloadBase64) {
|
||||
try {
|
||||
return decodeURIComponent(escape(atob(message.payloadBase64)));
|
||||
} catch {
|
||||
return message.payloadBase64;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function formatRocketMqMessagePayload(text: string): string {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed) return text;
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(trimmed), null, 2);
|
||||
} catch {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
export function rocketMqDisplayFromPeeked(msg: PeekedMessage, topic?: string): RocketMqDisplayMessage {
|
||||
const tagFromProps = msg.properties?.tag?.trim();
|
||||
const tagFromHeaders = msg.headers?.TAGS?.trim();
|
||||
return {
|
||||
messageId: msg.messageId,
|
||||
partition: peekedPropertyNumber(msg.properties, "partition"),
|
||||
offset: peekedPropertyNumber(msg.properties, "offset"),
|
||||
key: msg.key,
|
||||
tag: tagFromProps || tagFromHeaders || undefined,
|
||||
timestamp: msg.publishTime ? Number(msg.publishTime) : undefined,
|
||||
payloadText: msg.payloadText,
|
||||
payloadBase64: msg.payloadBase64,
|
||||
headers: msg.headers,
|
||||
topic,
|
||||
};
|
||||
}
|
||||
|
||||
export function rocketMqMessageToPeeked(message: RocketMqDisplayMessage, position: number): PeekedMessage {
|
||||
const properties: Record<string, string> = {};
|
||||
if (message.partition != null) properties.partition = String(message.partition);
|
||||
if (message.offset != null) properties.offset = String(message.offset);
|
||||
if (message.tag) properties.tag = message.tag;
|
||||
return {
|
||||
position,
|
||||
messageId: message.messageId ?? (message.offset != null ? String(message.offset) : undefined),
|
||||
key: message.key,
|
||||
publishTime: message.timestamp != null ? String(message.timestamp) : undefined,
|
||||
eventTime: undefined,
|
||||
properties,
|
||||
headers: message.headers ?? {},
|
||||
payloadBase64: message.payloadBase64 ?? "",
|
||||
payloadText: message.payloadText,
|
||||
};
|
||||
}
|
||||
|
||||
export function formatRocketMqTimestamp(value?: string | number): string {
|
||||
if (value == null || value === "") return "-";
|
||||
const numeric = typeof value === "number" ? value : Number(value);
|
||||
if (!Number.isFinite(numeric)) return String(value);
|
||||
return new Date(numeric).toLocaleString();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import type { RocketMqTopicMessageType, TopicInfo } from "@/types/mq";
|
||||
|
||||
export const ROCKETMQ_TOPIC_MESSAGE_TYPES: readonly RocketMqTopicMessageType[] = ["NORMAL", "DELAY", "FIFO", "TRANSACTION", "UNSPECIFIED", "RETRY", "DLQ", "SYSTEM"];
|
||||
|
||||
export const ROCKETMQ_CREATABLE_TOPIC_MESSAGE_TYPES: readonly RocketMqTopicMessageType[] = ["NORMAL", "DELAY", "FIFO", "TRANSACTION"];
|
||||
|
||||
export const DEFAULT_ROCKETMQ_TOPIC_TYPE_FILTERS: Record<RocketMqTopicMessageType, boolean> = {
|
||||
NORMAL: true,
|
||||
DELAY: true,
|
||||
FIFO: true,
|
||||
TRANSACTION: true,
|
||||
UNSPECIFIED: true,
|
||||
RETRY: false,
|
||||
DLQ: false,
|
||||
SYSTEM: false,
|
||||
};
|
||||
|
||||
export function resolveRocketMqMessageType(topic: Pick<TopicInfo, "messageType" | "internal">): RocketMqTopicMessageType {
|
||||
const raw = topic.messageType?.trim().toUpperCase();
|
||||
if (raw === "ORDER") return "FIFO";
|
||||
if (raw && ROCKETMQ_TOPIC_MESSAGE_TYPES.includes(raw as RocketMqTopicMessageType)) {
|
||||
return raw as RocketMqTopicMessageType;
|
||||
}
|
||||
if (topic.internal) return "SYSTEM";
|
||||
return "UNSPECIFIED";
|
||||
}
|
||||
|
||||
export function isRocketMqBusinessMessageType(type: RocketMqTopicMessageType): boolean {
|
||||
return type !== "SYSTEM" && type !== "RETRY" && type !== "DLQ";
|
||||
}
|
||||
|
||||
export function isProtectedRocketMqTopic(topic: Pick<TopicInfo, "messageType" | "internal">): boolean {
|
||||
return !isRocketMqBusinessMessageType(resolveRocketMqMessageType(topic));
|
||||
}
|
||||
|
||||
/** Default RocketMQ system trace topic; most clusters use this unless trace storage is customized. */
|
||||
export const DEFAULT_ROCKETMQ_TRACE_TOPIC = "RMQ_SYS_TRACE_TOPIC";
|
||||
|
||||
/** Build selectable trace topic names from cluster metadata. */
|
||||
export function buildRocketMqTraceTopicOptions(topics: Pick<TopicInfo, "shortName" | "messageType" | "internal">[]): string[] {
|
||||
const options = new Set<string>([DEFAULT_ROCKETMQ_TRACE_TOPIC]);
|
||||
for (const topic of topics) {
|
||||
const name = topic.shortName.trim();
|
||||
if (!name) continue;
|
||||
const type = resolveRocketMqMessageType(topic);
|
||||
if (type === "SYSTEM" || /trace/i.test(name)) {
|
||||
options.add(name);
|
||||
}
|
||||
}
|
||||
return [...options].sort((left, right) => {
|
||||
if (left === DEFAULT_ROCKETMQ_TRACE_TOPIC) return -1;
|
||||
if (right === DEFAULT_ROCKETMQ_TRACE_TOPIC) return 1;
|
||||
return left.localeCompare(right);
|
||||
});
|
||||
}
|
||||
|
||||
export function matchesRocketMqTypeFilters(topic: Pick<TopicInfo, "messageType" | "internal">, filters: Record<RocketMqTopicMessageType, boolean>): boolean {
|
||||
return filters[resolveRocketMqMessageType(topic)] === true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
|
||||
/** RocketMQ CODE 17: trace topic has no route on NameServer (trace not enabled or wrong topic). */
|
||||
export function isRocketMqTraceTopicRouteMissingError(error: unknown): boolean {
|
||||
const message = formatError(error);
|
||||
return /CODE:\s*17/i.test(message) && /not matched route info|No topic route info/i.test(message);
|
||||
}
|
||||
|
||||
export function formatRocketMqTraceError(error: unknown, traceTopicMissingHint: string): string {
|
||||
if (isRocketMqTraceTopicRouteMissingError(error)) {
|
||||
return traceTopicMissingHint;
|
||||
}
|
||||
return formatError(error);
|
||||
}
|
||||
Reference in new issue
Block a user