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