rocketmq-client-rust 1.0.0

Rust implementation of Apache rocketmq client
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// Copyright 2023 The RocketMQ Rust Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;

use cheetah_string::CheetahString;
use rocketmq_model::common::message::message_ext::MessageExt;
use rocketmq_model::common::message::message_queue::MessageQueue;
use rocketmq_protocol::protocol::admin::consume_stats::ConsumeStats;
use rocketmq_protocol::protocol::admin::topic_stats_table::TopicStatsTable;
use rocketmq_protocol::protocol::body::broker_body::cluster_info::ClusterInfo;
use rocketmq_protocol::protocol::body::consume_message_directly_result::ConsumeMessageDirectlyResult;
use rocketmq_protocol::protocol::body::consumer_connection::ConsumerConnection;
use rocketmq_protocol::protocol::body::consumer_running_info::ConsumerRunningInfo;
use rocketmq_protocol::protocol::body::group_list::GroupList;
use rocketmq_protocol::protocol::body::queue_time_span::QueueTimeSpan;
use rocketmq_protocol::protocol::body::topic::topic_list::TopicList;
use rocketmq_protocol::protocol::header::consume_message_directly_result_request_header::ConsumeMessageDirectlyResultRequestHeader;
use rocketmq_protocol::protocol::header::create_topic_request_header::CreateTopicRequestHeader;
use rocketmq_protocol::protocol::header::delete_subscription_group_request_header::DeleteSubscriptionGroupRequestHeader;
use rocketmq_protocol::protocol::header::delete_topic_request_header::DeleteTopicRequestHeader;
use rocketmq_protocol::protocol::header::get_consume_stats_request_header::GetConsumeStatsRequestHeader;
use rocketmq_protocol::protocol::header::get_consumer_connection_list_request_header::GetConsumerConnectionListRequestHeader;
use rocketmq_protocol::protocol::header::get_consumer_running_info_request_header::GetConsumerRunningInfoRequestHeader;
use rocketmq_protocol::protocol::header::get_topic_stats_info_request_header::GetTopicStatsInfoRequestHeader;
use rocketmq_protocol::protocol::header::namesrv::kv_config_header::DeleteKVConfigRequestHeader;
use rocketmq_protocol::protocol::header::namesrv::topic_operation_header::DeleteTopicFromNamesrvRequestHeader;
use rocketmq_protocol::protocol::header::query_consume_time_span_request_header::QueryConsumeTimeSpanRequestHeader;
use rocketmq_protocol::protocol::header::query_message_request_header::QueryMessageRequestHeader;
use rocketmq_protocol::protocol::header::query_subscription_by_consumer_request_header::QuerySubscriptionByConsumerRequestHeader;
use rocketmq_protocol::protocol::header::query_topic_consume_by_who_request_header::QueryTopicConsumeByWhoRequestHeader;
use rocketmq_protocol::protocol::header::query_topics_by_consumer_request_header::QueryTopicsByConsumerRequestHeader;
use rocketmq_protocol::protocol::header::reset_offset_request_header::ResetOffsetRequestHeader;
use rocketmq_protocol::protocol::header::view_message_request_header::ViewMessageRequestHeader;
use rocketmq_protocol::protocol::heartbeat::subscription_data::SubscriptionData;
use rocketmq_protocol::protocol::subscription::subscription_group_config::SubscriptionGroupConfig;

#[trait_variant::make(MqClientAdmin: Send)]
pub trait MqClientAdminInner: Sync {
    /// Queries messages based on the provided request header.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `unique_key_flag` - Flag indicating if the unique key should be used.
    /// * `decompress_body` - Flag indicating if the message body should be decompressed.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing a vector of `MessageExt` or an error.
    async fn query_message(
        &self,
        address: &str,
        unique_key_flag: bool,
        decompress_body: bool,
        request_header: QueryMessageRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<Vec<MessageExt>>;

    /// Retrieves topic statistics information.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `TopicStatsTable` or an error.
    async fn get_topic_stats_info(
        &self,
        address: &str,
        request_header: GetTopicStatsInfoRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<TopicStatsTable>;

    /// Queries the consume time span for a topic.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing a vector of `QueueTimeSpan` or an error.
    async fn query_consume_time_span(
        &self,
        address: &str,
        request_header: QueryConsumeTimeSpanRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<Vec<QueueTimeSpan>>;

    /// Updates or creates a topic.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing topic parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result indicating success or failure.
    async fn update_or_create_topic(
        &self,
        address: &str,
        request_header: CreateTopicRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Updates or creates a subscription group.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `config` - The configuration for the subscription group.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result indicating success or failure.
    async fn update_or_create_subscription_group(
        &self,
        address: &str,
        config: SubscriptionGroupConfig,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Deletes a topic in the broker.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing topic parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result indicating success or failure.
    async fn delete_topic_in_broker(
        &self,
        address: &str,
        request_header: DeleteTopicRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Deletes multiple topics in a broker using the Java-compatible batch request.
    async fn delete_topic_in_broker_list(
        &self,
        address: &str,
        topic_list: Vec<CheetahString>,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Deletes a topic in the nameserver.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the nameserver.
    /// * `request_header` - The request header containing topic parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result indicating success or failure.
    async fn delete_topic_in_nameserver(
        &self,
        address: &str,
        request_header: DeleteTopicFromNamesrvRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Deletes a key-value configuration.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the nameserver.
    /// * `request_header` - The request header containing key-value parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result indicating success or failure.
    async fn delete_kv_config(
        &self,
        address: &str,
        request_header: DeleteKVConfigRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Deletes a subscription group.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing subscription group parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result indicating success or failure.
    async fn delete_subscription_group(
        &self,
        address: &str,
        request_header: DeleteSubscriptionGroupRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Deletes multiple subscription groups in a broker using one request.
    async fn delete_subscription_group_list(
        &self,
        address: &str,
        group_name_list: Vec<CheetahString>,
        clean_offset: bool,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    /// Invokes the broker to reset the offset.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing reset offset parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing a hashmap of `MessageQueue` to offset or an error.
    async fn invoke_broker_to_reset_offset(
        &self,
        address: &str,
        request_header: ResetOffsetRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<HashMap<MessageQueue, i64>>;

    /// Views a message.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing view message parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `MessageExt` or an error.
    async fn view_message(
        &self,
        address: &str,
        request_header: ViewMessageRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<MessageExt>;

    /// Retrieves broker cluster information.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `ClusterInfo` or an error.
    async fn get_broker_cluster_info(&self, address: &str, timeout_millis: u64) -> crate::ClientResult<ClusterInfo>;

    /// Retrieves the consumer connection list.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing consumer connection parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `ConsumerConnection` or an error.
    async fn get_consumer_connection_list(
        &self,
        address: &str,
        request_header: GetConsumerConnectionListRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<ConsumerConnection>;

    /// Queries topics by consumer.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `TopicList` or an error.
    async fn query_topics_by_consumer(
        &self,
        address: &str,
        request_header: QueryTopicsByConsumerRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<TopicList>;

    /// Queries subscription by consumer.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `SubscriptionData` or an error.
    async fn query_subscription_by_consumer(
        &self,
        address: &str,
        request_header: QuerySubscriptionByConsumerRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<SubscriptionData>;

    /// Retrieves consume statistics.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `ConsumeStats` or an error.
    async fn get_consume_stats(
        &self,
        address: &str,
        request_header: GetConsumeStatsRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<ConsumeStats>;

    /// Queries which group consumes a topic.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `GroupList` or an error.
    async fn query_topic_consume_by_who(
        &self,
        address: &str,
        request_header: QueryTopicConsumeByWhoRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<GroupList>;

    /// Retrieves consumer running information.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing query parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `ConsumerRunningInfo` or an error.
    async fn get_consumer_running_info(
        &self,
        address: &str,
        request_header: GetConsumerRunningInfoRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<ConsumerRunningInfo>;

    /// Consumes a message directly.
    ///
    /// # Arguments
    ///
    /// * `address` - The address of the broker.
    /// * `request_header` - The request header containing consume message parameters.
    /// * `timeout_millis` - The timeout in milliseconds for the operation.
    ///
    /// # Returns
    ///
    /// A result containing `ConsumeMessageDirectlyResult` or an error.
    async fn consume_message_directly(
        &self,
        address: &str,
        request_header: ConsumeMessageDirectlyResultRequestHeader,
        timeout_millis: u64,
    ) -> crate::ClientResult<ConsumeMessageDirectlyResult>;
}