rocketmq_client_rust/base/mq_client_admin.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
15use std::collections::HashMap;
16
17use cheetah_string::CheetahString;
18use rocketmq_model::common::message::message_ext::MessageExt;
19use rocketmq_model::common::message::message_queue::MessageQueue;
20use rocketmq_protocol::protocol::admin::consume_stats::ConsumeStats;
21use rocketmq_protocol::protocol::admin::topic_stats_table::TopicStatsTable;
22use rocketmq_protocol::protocol::body::broker_body::cluster_info::ClusterInfo;
23use rocketmq_protocol::protocol::body::consume_message_directly_result::ConsumeMessageDirectlyResult;
24use rocketmq_protocol::protocol::body::consumer_connection::ConsumerConnection;
25use rocketmq_protocol::protocol::body::consumer_running_info::ConsumerRunningInfo;
26use rocketmq_protocol::protocol::body::group_list::GroupList;
27use rocketmq_protocol::protocol::body::queue_time_span::QueueTimeSpan;
28use rocketmq_protocol::protocol::body::topic::topic_list::TopicList;
29use rocketmq_protocol::protocol::header::consume_message_directly_result_request_header::ConsumeMessageDirectlyResultRequestHeader;
30use rocketmq_protocol::protocol::header::create_topic_request_header::CreateTopicRequestHeader;
31use rocketmq_protocol::protocol::header::delete_subscription_group_request_header::DeleteSubscriptionGroupRequestHeader;
32use rocketmq_protocol::protocol::header::delete_topic_request_header::DeleteTopicRequestHeader;
33use rocketmq_protocol::protocol::header::get_consume_stats_request_header::GetConsumeStatsRequestHeader;
34use rocketmq_protocol::protocol::header::get_consumer_connection_list_request_header::GetConsumerConnectionListRequestHeader;
35use rocketmq_protocol::protocol::header::get_consumer_running_info_request_header::GetConsumerRunningInfoRequestHeader;
36use rocketmq_protocol::protocol::header::get_topic_stats_info_request_header::GetTopicStatsInfoRequestHeader;
37use rocketmq_protocol::protocol::header::namesrv::kv_config_header::DeleteKVConfigRequestHeader;
38use rocketmq_protocol::protocol::header::namesrv::topic_operation_header::DeleteTopicFromNamesrvRequestHeader;
39use rocketmq_protocol::protocol::header::query_consume_time_span_request_header::QueryConsumeTimeSpanRequestHeader;
40use rocketmq_protocol::protocol::header::query_message_request_header::QueryMessageRequestHeader;
41use rocketmq_protocol::protocol::header::query_subscription_by_consumer_request_header::QuerySubscriptionByConsumerRequestHeader;
42use rocketmq_protocol::protocol::header::query_topic_consume_by_who_request_header::QueryTopicConsumeByWhoRequestHeader;
43use rocketmq_protocol::protocol::header::query_topics_by_consumer_request_header::QueryTopicsByConsumerRequestHeader;
44use rocketmq_protocol::protocol::header::reset_offset_request_header::ResetOffsetRequestHeader;
45use rocketmq_protocol::protocol::header::view_message_request_header::ViewMessageRequestHeader;
46use rocketmq_protocol::protocol::heartbeat::subscription_data::SubscriptionData;
47use rocketmq_protocol::protocol::subscription::subscription_group_config::SubscriptionGroupConfig;
48
49#[trait_variant::make(MqClientAdmin: Send)]
50pub trait MqClientAdminInner: Sync {
51 /// Queries messages based on the provided request header.
52 ///
53 /// # Arguments
54 ///
55 /// * `address` - The address of the broker.
56 /// * `unique_key_flag` - Flag indicating if the unique key should be used.
57 /// * `decompress_body` - Flag indicating if the message body should be decompressed.
58 /// * `request_header` - The request header containing query parameters.
59 /// * `timeout_millis` - The timeout in milliseconds for the operation.
60 ///
61 /// # Returns
62 ///
63 /// A result containing a vector of `MessageExt` or an error.
64 async fn query_message(
65 &self,
66 address: &str,
67 unique_key_flag: bool,
68 decompress_body: bool,
69 request_header: QueryMessageRequestHeader,
70 timeout_millis: u64,
71 ) -> crate::ClientResult<Vec<MessageExt>>;
72
73 /// Retrieves topic statistics information.
74 ///
75 /// # Arguments
76 ///
77 /// * `address` - The address of the broker.
78 /// * `request_header` - The request header containing query parameters.
79 /// * `timeout_millis` - The timeout in milliseconds for the operation.
80 ///
81 /// # Returns
82 ///
83 /// A result containing `TopicStatsTable` or an error.
84 async fn get_topic_stats_info(
85 &self,
86 address: &str,
87 request_header: GetTopicStatsInfoRequestHeader,
88 timeout_millis: u64,
89 ) -> crate::ClientResult<TopicStatsTable>;
90
91 /// Queries the consume time span for a topic.
92 ///
93 /// # Arguments
94 ///
95 /// * `address` - The address of the broker.
96 /// * `request_header` - The request header containing query parameters.
97 /// * `timeout_millis` - The timeout in milliseconds for the operation.
98 ///
99 /// # Returns
100 ///
101 /// A result containing a vector of `QueueTimeSpan` or an error.
102 async fn query_consume_time_span(
103 &self,
104 address: &str,
105 request_header: QueryConsumeTimeSpanRequestHeader,
106 timeout_millis: u64,
107 ) -> crate::ClientResult<Vec<QueueTimeSpan>>;
108
109 /// Updates or creates a topic.
110 ///
111 /// # Arguments
112 ///
113 /// * `address` - The address of the broker.
114 /// * `request_header` - The request header containing topic parameters.
115 /// * `timeout_millis` - The timeout in milliseconds for the operation.
116 ///
117 /// # Returns
118 ///
119 /// A result indicating success or failure.
120 async fn update_or_create_topic(
121 &self,
122 address: &str,
123 request_header: CreateTopicRequestHeader,
124 timeout_millis: u64,
125 ) -> crate::ClientResult<()>;
126
127 /// Updates or creates a subscription group.
128 ///
129 /// # Arguments
130 ///
131 /// * `address` - The address of the broker.
132 /// * `config` - The configuration for the subscription group.
133 /// * `timeout_millis` - The timeout in milliseconds for the operation.
134 ///
135 /// # Returns
136 ///
137 /// A result indicating success or failure.
138 async fn update_or_create_subscription_group(
139 &self,
140 address: &str,
141 config: SubscriptionGroupConfig,
142 timeout_millis: u64,
143 ) -> crate::ClientResult<()>;
144
145 /// Deletes a topic in the broker.
146 ///
147 /// # Arguments
148 ///
149 /// * `address` - The address of the broker.
150 /// * `request_header` - The request header containing topic parameters.
151 /// * `timeout_millis` - The timeout in milliseconds for the operation.
152 ///
153 /// # Returns
154 ///
155 /// A result indicating success or failure.
156 async fn delete_topic_in_broker(
157 &self,
158 address: &str,
159 request_header: DeleteTopicRequestHeader,
160 timeout_millis: u64,
161 ) -> crate::ClientResult<()>;
162
163 /// Deletes multiple topics in a broker using the Java-compatible batch request.
164 async fn delete_topic_in_broker_list(
165 &self,
166 address: &str,
167 topic_list: Vec<CheetahString>,
168 timeout_millis: u64,
169 ) -> crate::ClientResult<()>;
170
171 /// Deletes a topic in the nameserver.
172 ///
173 /// # Arguments
174 ///
175 /// * `address` - The address of the nameserver.
176 /// * `request_header` - The request header containing topic parameters.
177 /// * `timeout_millis` - The timeout in milliseconds for the operation.
178 ///
179 /// # Returns
180 ///
181 /// A result indicating success or failure.
182 async fn delete_topic_in_nameserver(
183 &self,
184 address: &str,
185 request_header: DeleteTopicFromNamesrvRequestHeader,
186 timeout_millis: u64,
187 ) -> crate::ClientResult<()>;
188
189 /// Deletes a key-value configuration.
190 ///
191 /// # Arguments
192 ///
193 /// * `address` - The address of the nameserver.
194 /// * `request_header` - The request header containing key-value parameters.
195 /// * `timeout_millis` - The timeout in milliseconds for the operation.
196 ///
197 /// # Returns
198 ///
199 /// A result indicating success or failure.
200 async fn delete_kv_config(
201 &self,
202 address: &str,
203 request_header: DeleteKVConfigRequestHeader,
204 timeout_millis: u64,
205 ) -> crate::ClientResult<()>;
206
207 /// Deletes a subscription group.
208 ///
209 /// # Arguments
210 ///
211 /// * `address` - The address of the broker.
212 /// * `request_header` - The request header containing subscription group parameters.
213 /// * `timeout_millis` - The timeout in milliseconds for the operation.
214 ///
215 /// # Returns
216 ///
217 /// A result indicating success or failure.
218 async fn delete_subscription_group(
219 &self,
220 address: &str,
221 request_header: DeleteSubscriptionGroupRequestHeader,
222 timeout_millis: u64,
223 ) -> crate::ClientResult<()>;
224
225 /// Deletes multiple subscription groups in a broker using one request.
226 async fn delete_subscription_group_list(
227 &self,
228 address: &str,
229 group_name_list: Vec<CheetahString>,
230 clean_offset: bool,
231 timeout_millis: u64,
232 ) -> crate::ClientResult<()>;
233
234 /// Invokes the broker to reset the offset.
235 ///
236 /// # Arguments
237 ///
238 /// * `address` - The address of the broker.
239 /// * `request_header` - The request header containing reset offset parameters.
240 /// * `timeout_millis` - The timeout in milliseconds for the operation.
241 ///
242 /// # Returns
243 ///
244 /// A result containing a hashmap of `MessageQueue` to offset or an error.
245 async fn invoke_broker_to_reset_offset(
246 &self,
247 address: &str,
248 request_header: ResetOffsetRequestHeader,
249 timeout_millis: u64,
250 ) -> crate::ClientResult<HashMap<MessageQueue, i64>>;
251
252 /// Views a message.
253 ///
254 /// # Arguments
255 ///
256 /// * `address` - The address of the broker.
257 /// * `request_header` - The request header containing view message parameters.
258 /// * `timeout_millis` - The timeout in milliseconds for the operation.
259 ///
260 /// # Returns
261 ///
262 /// A result containing `MessageExt` or an error.
263 async fn view_message(
264 &self,
265 address: &str,
266 request_header: ViewMessageRequestHeader,
267 timeout_millis: u64,
268 ) -> crate::ClientResult<MessageExt>;
269
270 /// Retrieves broker cluster information.
271 ///
272 /// # Arguments
273 ///
274 /// * `address` - The address of the broker.
275 /// * `timeout_millis` - The timeout in milliseconds for the operation.
276 ///
277 /// # Returns
278 ///
279 /// A result containing `ClusterInfo` or an error.
280 async fn get_broker_cluster_info(&self, address: &str, timeout_millis: u64) -> crate::ClientResult<ClusterInfo>;
281
282 /// Retrieves the consumer connection list.
283 ///
284 /// # Arguments
285 ///
286 /// * `address` - The address of the broker.
287 /// * `request_header` - The request header containing consumer connection parameters.
288 /// * `timeout_millis` - The timeout in milliseconds for the operation.
289 ///
290 /// # Returns
291 ///
292 /// A result containing `ConsumerConnection` or an error.
293 async fn get_consumer_connection_list(
294 &self,
295 address: &str,
296 request_header: GetConsumerConnectionListRequestHeader,
297 timeout_millis: u64,
298 ) -> crate::ClientResult<ConsumerConnection>;
299
300 /// Queries topics by consumer.
301 ///
302 /// # Arguments
303 ///
304 /// * `address` - The address of the broker.
305 /// * `request_header` - The request header containing query parameters.
306 /// * `timeout_millis` - The timeout in milliseconds for the operation.
307 ///
308 /// # Returns
309 ///
310 /// A result containing `TopicList` or an error.
311 async fn query_topics_by_consumer(
312 &self,
313 address: &str,
314 request_header: QueryTopicsByConsumerRequestHeader,
315 timeout_millis: u64,
316 ) -> crate::ClientResult<TopicList>;
317
318 /// Queries subscription by consumer.
319 ///
320 /// # Arguments
321 ///
322 /// * `address` - The address of the broker.
323 /// * `request_header` - The request header containing query parameters.
324 /// * `timeout_millis` - The timeout in milliseconds for the operation.
325 ///
326 /// # Returns
327 ///
328 /// A result containing `SubscriptionData` or an error.
329 async fn query_subscription_by_consumer(
330 &self,
331 address: &str,
332 request_header: QuerySubscriptionByConsumerRequestHeader,
333 timeout_millis: u64,
334 ) -> crate::ClientResult<SubscriptionData>;
335
336 /// Retrieves consume statistics.
337 ///
338 /// # Arguments
339 ///
340 /// * `address` - The address of the broker.
341 /// * `request_header` - The request header containing query parameters.
342 /// * `timeout_millis` - The timeout in milliseconds for the operation.
343 ///
344 /// # Returns
345 ///
346 /// A result containing `ConsumeStats` or an error.
347 async fn get_consume_stats(
348 &self,
349 address: &str,
350 request_header: GetConsumeStatsRequestHeader,
351 timeout_millis: u64,
352 ) -> crate::ClientResult<ConsumeStats>;
353
354 /// Queries which group consumes a topic.
355 ///
356 /// # Arguments
357 ///
358 /// * `address` - The address of the broker.
359 /// * `request_header` - The request header containing query parameters.
360 /// * `timeout_millis` - The timeout in milliseconds for the operation.
361 ///
362 /// # Returns
363 ///
364 /// A result containing `GroupList` or an error.
365 async fn query_topic_consume_by_who(
366 &self,
367 address: &str,
368 request_header: QueryTopicConsumeByWhoRequestHeader,
369 timeout_millis: u64,
370 ) -> crate::ClientResult<GroupList>;
371
372 /// Retrieves consumer running information.
373 ///
374 /// # Arguments
375 ///
376 /// * `address` - The address of the broker.
377 /// * `request_header` - The request header containing query parameters.
378 /// * `timeout_millis` - The timeout in milliseconds for the operation.
379 ///
380 /// # Returns
381 ///
382 /// A result containing `ConsumerRunningInfo` or an error.
383 async fn get_consumer_running_info(
384 &self,
385 address: &str,
386 request_header: GetConsumerRunningInfoRequestHeader,
387 timeout_millis: u64,
388 ) -> crate::ClientResult<ConsumerRunningInfo>;
389
390 /// Consumes a message directly.
391 ///
392 /// # Arguments
393 ///
394 /// * `address` - The address of the broker.
395 /// * `request_header` - The request header containing consume message parameters.
396 /// * `timeout_millis` - The timeout in milliseconds for the operation.
397 ///
398 /// # Returns
399 ///
400 /// A result containing `ConsumeMessageDirectlyResult` or an error.
401 async fn consume_message_directly(
402 &self,
403 address: &str,
404 request_header: ConsumeMessageDirectlyResultRequestHeader,
405 timeout_millis: u64,
406 ) -> crate::ClientResult<ConsumeMessageDirectlyResult>;
407}