rocketmq_client_rust/base/
mq_admin.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17use std::collections::HashMap;
18
19use rocketmq_common::common::message::message_ext::MessageExt;
20use rocketmq_common::common::message::message_queue::MessageQueue;
21
22use crate::base::query_result::QueryResult;
23
24/// Trait defining administrative operations for a Message Queue (MQ).
25#[allow(dead_code)]
26pub trait MQAdmin {
27    /// Creates a new topic.
28    ///
29    /// # Arguments
30    /// * `key` - A key used for topic creation.
31    /// * `new_topic` - The name of the new topic.
32    /// * `queue_num` - The number of queues for the new topic.
33    /// * `attributes` - A map of attributes for the new topic.
34    ///
35    /// # Returns
36    /// A `Result` indicating success or failure.
37    fn create_topic(
38        &self,
39        key: &str,
40        new_topic: &str,
41        queue_num: i32,
42        attributes: HashMap<String, String>,
43    ) -> rocketmq_error::RocketMQResult<()>;
44
45    /// Creates a new topic with a system flag.
46    ///
47    /// # Arguments
48    /// * `key` - A key used for topic creation.
49    /// * `new_topic` - The name of the new topic.
50    /// * `queue_num` - The number of queues for the new topic.
51    /// * `topic_sys_flag` - The system flag for the new topic.
52    /// * `attributes` - A map of attributes for the new topic.
53    ///
54    /// # Returns
55    /// A `Result` indicating success or failure.
56    fn create_topic_with_flag(
57        &self,
58        key: &str,
59        new_topic: &str,
60        queue_num: i32,
61        topic_sys_flag: i32,
62        attributes: HashMap<String, String>,
63    ) -> rocketmq_error::RocketMQResult<()>;
64
65    /// Searches for the offset of a message in a queue at a given timestamp.
66    ///
67    /// # Arguments
68    /// * `mq` - The message queue to search.
69    /// * `timestamp` - The timestamp to search for.
70    ///
71    /// # Returns
72    /// A `Result` containing the offset if found, or an error.
73    fn search_offset(
74        &self,
75        mq: &MessageQueue,
76        timestamp: u64,
77    ) -> rocketmq_error::RocketMQResult<i64>;
78
79    /// Retrieves the maximum offset of a message in a queue.
80    ///
81    /// # Arguments
82    /// * `mq` - The message queue to query.
83    ///
84    /// # Returns
85    /// A `Result` containing the maximum offset, or an error.
86    fn max_offset(&self, mq: &MessageQueue) -> rocketmq_error::RocketMQResult<i64>;
87
88    /// Retrieves the minimum offset of a message in a queue.
89    ///
90    /// # Arguments
91    /// * `mq` - The message queue to query.
92    ///
93    /// # Returns
94    /// A `Result` containing the minimum offset, or an error.
95    fn min_offset(&self, mq: &MessageQueue) -> rocketmq_error::RocketMQResult<i64>;
96
97    /// Retrieves the earliest message store time in a queue.
98    ///
99    /// # Arguments
100    /// * `mq` - The message queue to query.
101    ///
102    /// # Returns
103    /// A `Result` containing the earliest message store time, or an error.
104    fn earliest_msg_store_time(&self, mq: &MessageQueue) -> rocketmq_error::RocketMQResult<u64>;
105
106    /// Queries messages in a topic by key within a time range.
107    ///
108    /// # Arguments
109    /// * `topic` - The topic to query.
110    /// * `key` - The key to search for.
111    /// * `max_num` - The maximum number of messages to return.
112    /// * `begin` - The start of the time range.
113    /// * `end` - The end of the time range.
114    ///
115    /// # Returns
116    /// A `Result` containing a `QueryResult` with the messages, or an error.
117    fn query_message(
118        &self,
119        topic: &str,
120        key: &str,
121        max_num: i32,
122        begin: u64,
123        end: u64,
124    ) -> rocketmq_error::RocketMQResult<QueryResult>;
125
126    /// Views a message by its ID in a topic.
127    ///
128    /// # Arguments
129    /// * `topic` - The topic containing the message.
130    /// * `msg_id` - The ID of the message to view.
131    ///
132    /// # Returns
133    /// A `Result` containing the `MessageExt` if found, or an error.
134    fn view_message(&self, topic: &str, msg_id: &str)
135        -> rocketmq_error::RocketMQResult<MessageExt>;
136}