Skip to main content

rocketmq_admin_core/
lib.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![recursion_limit = "256"]
16
17//! RocketMQ Tools - Admin and CLI utilities
18//!
19//! This crate provides both:
20//! - **Core**: Reusable business logic for RocketMQ operations
21//! - **CLI**: Command-line interface with formatting and validation
22//!
23//! # Architecture
24//!
25//! ```text
26//! ┌─────────────────────────────────────────┐
27//! │           CLI Layer (bin/)              │
28//! │  - Command parsing (clap)               │
29//! │  - Output formatting (formatters/)      │
30//! │  - Input validation (validators/)       │
31//! └─────────────────┬───────────────────────┘
32//!                   │
33//!                   ▼
34//! ┌─────────────────────────────────────────┐
35//! │         Core Logic (core/)              │
36//! │  - Topic operations                     │
37//! │  - NameServer operations                │
38//! │  - Broker operations (future)           │
39//! │  - Consumer operations (future)         │
40//! └─────────────────┬───────────────────────┘
41//!                   │
42//!                   ▼
43//! ┌─────────────────────────────────────────┐
44//! │        Admin API (admin/)               │
45//! │  - DefaultMQAdminExt                    │
46//! │  - MQAdminExt trait implementations     │
47//! └─────────────────────────────────────────┘
48//! ```
49//!
50//! # Usage Examples
51//!
52//! ## As a Library (using core)
53//!
54//! ```rust,ignore
55//! use rocketmq_admin_core::core::admin::AdminBuilder;
56//! use rocketmq_admin_core::core::topic::TopicService;
57//!
58//! // With RAII auto-cleanup
59//! let mut admin = AdminBuilder::new()
60//!     .namesrv_addr("127.0.0.1:9876")
61//!     .build_with_guard()
62//!     .await?;
63//!
64//! let clusters = TopicService::get_topic_cluster_list(&mut admin, "MyTopic").await?;
65//! // admin automatically cleaned up here
66//! ```
67//!
68//! ## As a CLI Tool
69//!
70//! ```bash
71//! rocketmq-admin-cli-rust topic topicClusterList -t MyTopic -n 127.0.0.1:9876
72//! ```
73
74// Core business logic - reusable across different interfaces
75pub mod core {
76    //! Core business logic module
77    //!
78    //! This module contains reusable business logic that is independent of
79    //! any presentation layer (CLI, API, TUI, etc.).
80    //!
81    //! # Design Principles
82    //!
83    //! 1. **Pure Business Logic**: No I/O, no formatting, no CLI concerns
84    //! 2. **Testable**: Can be tested independently without CLI
85    //! 3. **Reusable**: Can be used by different interfaces
86    //! 4. **Type-Safe**: Uses strong types and Result for error handling
87    //!
88    //! # Available Modules
89    //!
90    //! - [`admin`] - Admin client builder and RAII management
91    //! - [`topic`] - Topic management operations
92    //! - [`namesrv`] - NameServer management operations
93
94    pub mod admin;
95    pub mod cache;
96    pub mod concurrent;
97    pub mod namesrv;
98    pub mod topic;
99
100    // Re-export error types from rocketmq-error
101    pub use rocketmq_error::RocketMQError;
102    pub use rocketmq_error::RocketMQResult;
103    pub use rocketmq_error::ToolsError;
104
105    // Future modules (uncomment when implemented):
106    // pub mod broker;
107    // pub mod consumer;
108    // pub mod message;
109    // pub mod stats;
110}
111
112// CLI presentation layer
113pub mod cli {
114    //! CLI presentation layer
115    //!
116    //! This module contains everything related to the command-line interface:
117    //! - [`commands`] - Command definitions and parsing
118    //! - [`formatters`] - Output formatters (JSON, YAML, Table)
119    //! - [`validators`] - Input validators
120    //!
121    //! The CLI layer is a thin wrapper around the core business logic,
122    //! handling user interaction concerns separately from business logic.
123    //!
124    //! # Architecture
125    //!
126    //! ```text
127    //! CLI Layer (this module)
128    //!     ↓
129    //! Core Business Logic (../core)
130    //!     ↓
131    //! Admin API (../admin)
132    //! ```
133
134    pub mod commands;
135    pub mod formatters;
136    pub mod validators;
137}
138
139// UI utilities for enhanced CLI experience
140pub mod ui;
141
142// Admin API layer
143pub mod admin;
144
145// Legacy command structure (will be gradually migrated)
146pub(crate) mod commands;
147
148// CLI entry point
149pub mod rocketmq_cli;