Files
dbx/crates/dbx-core/src/mq/port.rs
T
miracleandt8y2 2a59d3143e feat(mq): implement Apache Pulsar message queue admin
* feat(mq): implement Apache Pulsar message queue admin

- Add complete MQ admin adapter layer with version detection
  * Pulsar adapter with multi-version API support
  * OAuth2 token caching and authentication
  * JWT token signing for Pulsar clients
  * Transport layer (SSH/Proxy) integration

- Implement comprehensive admin operations
  * Tenant, namespace, topic management
  * Subscription and consumer/producer monitoring
  * Rate limits, backlog quotas, retention policies
  * Permissions and role-based access control
  * Raw admin API for advanced operations

- Add desktop UI components
  * MQ admin console with tabbed interface
  * Tenant, namespace, topic panels
  * Subscription management and cursor operations
  * Monitoring panel with stats visualization
  * Policy configuration UI

- Add web routes for MQ admin operations
- Add secret store support for MQ auth credentials
- Add comprehensive test coverage

* fix: del local test files

* fix(mq): mark message queue as unsupported mcpMode in driver manifest

MQ admin connections do not use the MCP query bridge - they use a
separate REST admin API. Mark mcpMode as 'unsupported' to align with
the test expectations and reflect the actual architecture.

Fixes CI test: driver-manifest.test.ts

* fix(mq): fix TypeScript errors in MQ components

- Fix typo in SubscriptionsPanel.vue: messagformatError(e)Id -> message.messageId
- Use formatError() helper in RawApiPanel.vue instead of accessing e?.message
- Fix undefined 'tab' reference in ConnectionTree.vue: use config.db_type instead

Fixes frontend CI TypeScript check errors.

* fix(mcp): add 'mq' to MCP server connection type description

The MCP server's connection type description must include all database
types from the driver manifest. Add 'mq' to the list to fix the test:
'add connection database type description includes every manifest database type'

Fixes: packages/mcp-server/tests/driver-manifest.test.ts

* fix(mq): add missing ConnectionConfig fields for Rust compilation

- Add gbase_server and keepalive_interval_secs fields to all ConnectionConfig
  test constructors in mq/config.rs, mq/service.rs, and storage.rs
- Import uses_bare_mysql_pool in connection.rs tests module

Fixes compilation errors from upstream ConnectionConfig changes.

* chore(ui): simplify Pulsar icon to logo-only version

Remove text from Pulsar icon (127x30 -> 35x30), keeping only
the wave logo symbol for a cleaner, more consistent appearance
with other database icons.

* fix(mq): return removed pools from drain_connection_pools

---------

Co-authored-by: t8y2 <1156263951@qq.com>
2026-06-16 21:57:17 +08:00

78 lines
4.7 KiB
Rust

//! The message queue admin port — the abstraction all MQ systems implement.
//!
//! Commands and routes program against this trait only; concrete systems
//! (Pulsar today, Kafka / RocketMQ later) live in `adapters/`.
use async_trait::async_trait;
use crate::mq::types::*;
/// Unified management interface for message queue systems.
#[async_trait]
pub trait MessageQueueAdmin: Send + Sync {
/// Capability flags so the frontend can show/hide functionality.
fn capabilities(&self) -> MqCapabilities;
fn system_kind(&self) -> MqSystemKind;
/// Connectivity test; returns cluster/version info.
async fn test_connection(&self) -> Result<MqClusterInfo, String>;
// ---- Tenants ----
async fn list_tenants(&self) -> Result<Vec<TenantInfo>, String>;
async fn get_tenant(&self, name: &str) -> Result<TenantInfo, String>;
async fn create_tenant(&self, name: &str, cfg: TenantConfig) -> Result<(), String>;
async fn update_tenant(&self, name: &str, cfg: TenantConfig) -> Result<(), String>;
async fn delete_tenant(&self, name: &str, force: bool) -> Result<(), String>;
// ---- Namespaces ----
async fn list_namespaces(&self, tenant: &str) -> Result<Vec<NamespaceInfo>, String>;
async fn create_namespace(&self, ns: &NamespaceRef, cfg: NamespaceConfig) -> Result<(), String>;
async fn delete_namespace(&self, ns: &NamespaceRef, force: bool) -> Result<(), String>;
async fn get_namespace_policies(&self, ns: &NamespaceRef) -> Result<serde_json::Value, String>;
// ---- Topics ----
async fn list_topics(&self, ns: &NamespaceRef, opts: ListTopicsOpts) -> Result<Vec<TopicInfo>, String>;
async fn create_topic(&self, topic: &TopicRef, partitions: Option<u32>) -> Result<(), String>;
async fn delete_topic(&self, topic: &TopicRef, force: bool) -> Result<(), String>;
async fn update_partitions(&self, topic: &TopicRef, partitions: u32) -> Result<(), String>;
async fn get_topic_stats(&self, topic: &TopicRef) -> Result<TopicStats, String>;
async fn get_topic_internal_stats(&self, topic: &TopicRef) -> Result<serde_json::Value, String>;
// ---- Subscriptions ----
async fn list_subscriptions(&self, topic: &TopicRef) -> Result<Vec<SubscriptionInfo>, String>;
async fn create_subscription(&self, topic: &TopicRef, sub: &str, pos: ResetPosition) -> Result<(), String>;
async fn delete_subscription(&self, topic: &TopicRef, sub: &str, force: bool) -> Result<(), String>;
async fn skip_messages(&self, topic: &TopicRef, sub: &str, count: SkipCount) -> Result<(), String>;
async fn reset_cursor(&self, topic: &TopicRef, sub: &str, pos: ResetPosition) -> Result<(), String>;
async fn clear_backlog(&self, topic: &TopicRef, sub: &str) -> Result<(), String>;
async fn peek_messages(&self, topic: &TopicRef, sub: &str, count: u32) -> Result<Vec<PeekedMessage>, String>;
async fn expire_messages(&self, topic: &TopicRef, sub: &str, expire_seconds: i64) -> Result<(), String>;
// ---- Producers / consumers (runtime, read from stats) ----
async fn list_producers(&self, topic: &TopicRef) -> Result<Vec<ProducerInfo>, String>;
async fn list_consumers(&self, topic: &TopicRef, sub: &str) -> Result<Vec<ConsumerInfo>, String>;
/// Unload a topic (Pulsar has no per-connection kill; unload is the closest).
async fn unload_topic(&self, topic: &TopicRef) -> Result<(), String>;
// ---- Rate limits / quotas / retention ----
async fn set_publish_rate(&self, scope: &PolicyScope, rate: PublishRate) -> Result<(), String>;
async fn set_dispatch_rate(&self, scope: &PolicyScope, rate: DispatchRate) -> Result<(), String>;
async fn set_subscribe_rate(&self, scope: &PolicyScope, rate: SubscribeRate) -> Result<(), String>;
async fn set_backlog_quota(&self, scope: &PolicyScope, quota: BacklogQuota) -> Result<(), String>;
async fn set_retention(&self, scope: &PolicyScope, retention: RetentionPolicy) -> Result<(), String>;
async fn get_effective_policies(&self, scope: &PolicyScope) -> Result<serde_json::Value, String>;
// ---- Permissions (who can produce / consume) ----
async fn grant_permission(&self, scope: &PolicyScope, role: &str, actions: Vec<AuthAction>) -> Result<(), String>;
async fn revoke_permission(&self, scope: &PolicyScope, role: &str) -> Result<(), String>;
async fn list_permissions(&self, scope: &PolicyScope) -> Result<PermissionMap, String>;
// ---- Monitoring ----
async fn get_backlog(&self, topic: &TopicRef, sub: Option<&str>) -> Result<BacklogStats, String>;
/// Escape hatch: proxy an arbitrary admin REST call. Covers any endpoint the
/// typed methods do not.
async fn raw_request(&self, req: MqRawRequest) -> Result<MqRawResponse, String>;
}