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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
// Copyright 2026 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.

//! Narrow administration mutation surface.
//!
//! Method names are intentionally distinct from the full administration
//! capability set, allowing mutation-only consumers to depend on an explicit
//! supervised capability.

use std::collections::HashMap;
use std::collections::HashSet;

use cheetah_string::CheetahString;
use rocketmq_model::common::config::TopicConfig;
use rocketmq_model::common::message::message_enum::MessageRequestMode;
use rocketmq_model::common::message::message_ext::MessageExt;
use rocketmq_model::common::message::message_queue::MessageQueue;
use rocketmq_protocol::protocol::admin::rollback_stats::RollbackStats;
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::proxy_drain::ProxyDrainStateResponseBody;
use rocketmq_protocol::protocol::route::topic_route_data::TopicRouteData;
use rocketmq_protocol::protocol::subscription::subscription_group_config::SubscriptionGroupConfig;

use super::default_mq_admin_ext::DefaultMQAdminExt;

/// Result of one generation-checked broker configuration patch.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum BrokerConfigPatchOutcome {
    /// The patch was committed as the generation immediately after precheck.
    Applied { previous_generation: u64, generation: u64 },
    /// The broker changed after precheck; callers must stop and re-plan.
    GenerationConflict {
        expected_generation: u64,
        actual_generation: u64,
    },
}

/// Closed Topic fields accepted by the supervised version-CAS operation.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct TopicConfigPatch {
    pub read_queue_nums: Option<u32>,
    pub write_queue_nums: Option<u32>,
    pub order: Option<bool>,
}

impl TopicConfigPatch {
    #[must_use]
    pub const fn is_empty(self) -> bool {
        self.read_queue_nums.is_none() && self.write_queue_nums.is_none() && self.order.is_none()
    }
}

/// Result of one version-checked Topic configuration patch.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TopicConfigPatchOutcome {
    /// The patch was committed as the version immediately after precheck.
    Applied { previous_version: u64, version: u64 },
    /// Topic metadata changed after precheck; callers must stop and re-plan.
    VersionConflict { expected_version: u64, actual_version: u64 },
}

/// Allowlisted Topic state returned to an isolated mutation preflight.
#[derive(Clone, Debug, PartialEq)]
pub struct MutationTopicConfigVersioned {
    pub version: u64,
    pub config: TopicConfig,
}

/// Closed presence/version condition for full supervised metadata replacement.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MutationExpectedState {
    Absent,
    Present { version: u64 },
}

/// Closed Topic message types supported by supervised replacement.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MutationTopicMessageType {
    Normal,
    Fifo,
    Delay,
    Transaction,
    Unspecified,
}

impl MutationTopicMessageType {
    pub(crate) const fn wire_name(self) -> &'static str {
        match self {
            Self::Normal => "NORMAL",
            Self::Fifo => "FIFO",
            Self::Delay => "DELAY",
            Self::Transaction => "TRANSACTION",
            Self::Unspecified => "UNSPECIFIED",
        }
    }
}

/// Complete allowlisted Topic state used by a supervised replace operation.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MutationTopicConfig {
    pub read_queue_nums: u32,
    pub write_queue_nums: u32,
    pub perm: u32,
    pub order: bool,
    pub message_type: MutationTopicMessageType,
}

/// Presence-aware Topic preflight result.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MutationTopicConfigState {
    pub state: MutationExpectedState,
    pub config: Option<MutationTopicConfig>,
}

/// Complete allowlisted Subscription Group state used by supervised replacement.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MutationSubscriptionGroupConfig {
    pub consume_enable: bool,
    pub consume_from_min_enable: bool,
    pub consume_broadcast_enable: bool,
    pub consume_message_orderly: bool,
    pub retry_queue_nums: i32,
    pub retry_max_times: i32,
    pub broker_id: u64,
    pub which_broker_when_consume_slowly: u64,
    pub notify_consumer_ids_changed_enable: bool,
    pub group_sys_flag: i32,
    pub consume_timeout_minute: i32,
}

/// Presence-aware Subscription Group preflight result.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MutationSubscriptionGroupConfigState {
    pub state: MutationExpectedState,
    pub config: Option<MutationSubscriptionGroupConfig>,
}

/// Result of one presence/version conditional replacement.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MutationStateCasOutcome {
    pub applied: bool,
    pub changed: bool,
    pub state: MutationExpectedState,
    pub persistence: MutationPersistenceState,
}

/// Durable state of an accepted supervised mutation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MutationPersistenceState {
    NotRequired,
    Persisted,
    /// The write is confirmed not to have reached the target file.
    Failed,
    /// The write may already have reached the target file; the Broker ended
    /// its observation without confirming either durability or failure.
    Unconfirmed,
}

/// Six-key Broker state allowed into mutation preflight.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct BrokerMutationConfigState {
    pub generation: u64,
    pub auto_create_topic_enable: bool,
    pub auto_create_subscription_group: bool,
    pub broker_permission: u32,
    pub default_topic_queue_nums: u32,
    pub message_index_enable: bool,
    pub trace_topic_enable: bool,
}

/// Exact conditional consumer-offset update result.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ConditionalConsumerOffsetOutcome {
    pub applied: bool,
    pub actual_offset: i64,
}

/// Pure preflight row for one logical Broker queue; no network address escapes.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MutationConsumerOffsetPreview {
    pub broker_name: String,
    pub queue_id: i32,
    pub current_offset: i64,
    pub planned_offset: i64,
}

/// Exact request-mode value returned by a selected Broker master.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MutationMessageRequestMode {
    pub mode: MessageRequestMode,
    pub pop_share_queue_num: i32,
}

/// Closed request-mode precondition.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MutationExpectedMessageRequestMode {
    Absent,
    Present(MutationMessageRequestMode),
}

/// Conditional request-mode result containing only the current typed value.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MutationMessageRequestModeOutcome {
    pub applied: bool,
    pub changed: bool,
    pub current: Option<MutationMessageRequestMode>,
    pub persistence: MutationPersistenceState,
}

/// Closed failure categories for one detailed consumer-offset target.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TopicOffsetMutationFailureCode {
    InvalidData,
    Unavailable,
}

/// One broker or queue result from a detailed reset/skip workflow.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TopicOffsetMutationTargetOutcome {
    pub broker_name: String,
    pub queue_id: Option<i32>,
    pub applied: bool,
    pub offset: Option<u64>,
    pub failure: Option<TopicOffsetMutationFailureCode>,
    pub retryable: bool,
}

/// Failure-aware results for all exact broker/queue targets reached by one offset mutation.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct TopicOffsetMutationOutcome {
    pub targets: Vec<TopicOffsetMutationTargetOutcome>,
}

/// Closed Subscription Group fields accepted by the supervised version-CAS
/// operation.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct SubscriptionGroupConfigPatch {
    pub retry_max_times: Option<u32>,
    pub retry_queue_nums: Option<u32>,
    pub consume_timeout_minutes: Option<u32>,
}

impl SubscriptionGroupConfigPatch {
    #[must_use]
    pub const fn is_empty(self) -> bool {
        self.retry_max_times.is_none() && self.retry_queue_nums.is_none() && self.consume_timeout_minutes.is_none()
    }
}

/// Result of one version-checked Subscription Group configuration patch.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SubscriptionGroupConfigPatchOutcome {
    /// The patch was committed as the version immediately after precheck.
    Applied { previous_version: u64, version: u64 },
    /// Subscription Group metadata changed after precheck; callers must stop
    /// and re-plan.
    VersionConflict { expected_version: u64, actual_version: u64 },
}

/// Explicit RocketMQ mutation capability.
///
/// New integrations should request this trait deliberately and keep it out of
/// read-only process dependency graphs.
#[allow(async_fn_in_trait)]
pub trait MQAdminMutationExt: Send {
    /// Begins one authenticated, reversible drain operation for a Proxy.
    async fn begin_proxy_drain(
        &self,
        proxy_addr: CheetahString,
        operation_id: CheetahString,
    ) -> crate::ClientResult<ProxyDrainStateResponseBody>;

    /// Cancels a timed-out drain and restores Proxy admission/readiness.
    async fn cancel_proxy_drain(
        &self,
        proxy_addr: CheetahString,
        operation_id: CheetahString,
    ) -> crate::ClientResult<ProxyDrainStateResponseBody>;

    /// Reads the broker configuration generation used by supervised prechecks.
    async fn broker_config_generation(&self, broker_addr: CheetahString) -> crate::ClientResult<u64>;

    /// Applies a broker configuration patch only when `expected_generation`
    /// still matches the broker's current generation.
    async fn patch_broker_config_if_generation(
        &self,
        broker_addr: CheetahString,
        expected_generation: u64,
        properties: HashMap<CheetahString, CheetahString>,
    ) -> crate::ClientResult<BrokerConfigPatchOutcome>;

    /// Changes only the three fields in [`TopicConfigPatch`] when the Broker's
    /// current Topic metadata version still matches `expected_version`.
    async fn patch_topic_config_if_version(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        expected_version: u64,
        patch: TopicConfigPatch,
    ) -> crate::ClientResult<TopicConfigPatchOutcome>;

    /// Reads only the Topic fields and version needed to prepare a supervised
    /// queue-count compare-and-set mutation.
    async fn mutation_topic_config_with_version(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
    ) -> crate::ClientResult<MutationTopicConfigVersioned> {
        let _ = (broker_addr, topic);
        Err(crate::ClientError::illegal_argument(
            "versioned Topic mutation preflight is not implemented by this admin client",
        ))
    }

    /// Reads a presence-aware, allowlisted Topic state from one exact Broker.
    async fn mutation_topic_config_state(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
    ) -> crate::ClientResult<MutationTopicConfigState> {
        let _ = (broker_addr, topic);
        Err(crate::ClientError::illegal_argument(
            "presence-aware Topic mutation preflight is not implemented by this admin client",
        ))
    }

    /// Creates or fully replaces the allowlisted Topic state only when its
    /// presence/version precondition still matches.
    async fn replace_topic_config_if_state(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        expected_state: MutationExpectedState,
        replacement: MutationTopicConfig,
    ) -> crate::ClientResult<MutationStateCasOutcome> {
        let _ = (broker_addr, topic, expected_state, replacement);
        Err(crate::ClientError::illegal_argument(
            "presence-aware Topic replacement is not implemented by this admin client",
        ))
    }

    /// Changes only the three fields in [`SubscriptionGroupConfigPatch`] when
    /// the Broker's current Subscription Group metadata version still matches
    /// `expected_version`.
    async fn patch_subscription_group_config_if_version(
        &self,
        broker_addr: CheetahString,
        group: CheetahString,
        expected_version: u64,
        patch: SubscriptionGroupConfigPatch,
    ) -> crate::ClientResult<SubscriptionGroupConfigPatchOutcome>;

    /// Reads presence-aware, allowlisted Subscription Group state from one exact Broker.
    async fn mutation_subscription_group_config_state(
        &self,
        broker_addr: CheetahString,
        group: CheetahString,
    ) -> crate::ClientResult<MutationSubscriptionGroupConfigState> {
        let _ = (broker_addr, group);
        Err(crate::ClientError::illegal_argument(
            "presence-aware Subscription Group mutation preflight is not implemented by this admin client",
        ))
    }

    /// Creates or fully replaces the allowlisted Subscription Group state under one state CAS.
    async fn replace_subscription_group_config_if_state(
        &self,
        broker_addr: CheetahString,
        group: CheetahString,
        expected_state: MutationExpectedState,
        replacement: MutationSubscriptionGroupConfig,
    ) -> crate::ClientResult<MutationStateCasOutcome> {
        let _ = (broker_addr, group, expected_state, replacement);
        Err(crate::ClientError::illegal_argument(
            "presence-aware Subscription Group replacement is not implemented by this admin client",
        ))
    }

    /// Reads only the six Broker settings accepted by supervised control preflight.
    async fn broker_mutation_config_state(
        &self,
        broker_addr: CheetahString,
    ) -> crate::ClientResult<BrokerMutationConfigState> {
        let _ = broker_addr;
        Err(crate::ClientError::illegal_argument(
            "allowlisted Broker mutation preflight is not implemented by this admin client",
        ))
    }

    /// Applies one exact queue offset transition without route re-resolution or retry.
    async fn reset_consumer_offset_if_current(
        &self,
        broker_addr: CheetahString,
        consumer_group: CheetahString,
        topic: CheetahString,
        queue_id: i32,
        expected_offset: i64,
        new_offset: i64,
    ) -> crate::ClientResult<ConditionalConsumerOffsetOutcome> {
        let _ = (
            broker_addr,
            consumer_group,
            topic,
            queue_id,
            expected_offset,
            new_offset,
        );
        Err(crate::ClientError::illegal_argument(
            "conditional consumer-offset mutation is not implemented by this admin client",
        ))
    }

    /// Computes exact queue offsets for one already-selected Broker master without mutation.
    async fn preview_consumer_offset_reset_on_broker(
        &self,
        broker_addr: CheetahString,
        broker_name: CheetahString,
        read_queue_nums: u32,
        consumer_group: CheetahString,
        topic: CheetahString,
        timestamp: i64,
    ) -> crate::ClientResult<Vec<MutationConsumerOffsetPreview>> {
        let _ = (
            broker_addr,
            broker_name,
            read_queue_nums,
            consumer_group,
            topic,
            timestamp,
        );
        Err(crate::ClientError::illegal_argument(
            "consumer-offset mutation preview is not implemented by this admin client",
        ))
    }

    /// Re-reads one exact queue offset for postcondition verification.
    async fn mutation_consumer_offset(
        &self,
        broker_addr: CheetahString,
        consumer_group: CheetahString,
        topic: CheetahString,
        queue_id: i32,
    ) -> crate::ClientResult<i64> {
        let _ = (broker_addr, consumer_group, topic, queue_id);
        Err(crate::ClientError::illegal_argument(
            "consumer-offset mutation verification is not implemented by this admin client",
        ))
    }

    /// Reads one exact Topic/group request-mode entry from a selected Broker master.
    async fn mutation_message_request_mode(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
    ) -> crate::ClientResult<Option<MutationMessageRequestMode>> {
        let _ = (broker_addr, topic, consumer_group);
        Err(crate::ClientError::illegal_argument(
            "request-mode mutation preflight is not implemented by this admin client",
        ))
    }

    /// Conditionally replaces one exact Topic/group request-mode entry.
    async fn replace_message_request_mode_if_current(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        expected: MutationExpectedMessageRequestMode,
        replacement: MutationMessageRequestMode,
    ) -> crate::ClientResult<MutationMessageRequestModeOutcome> {
        let _ = (broker_addr, topic, consumer_group, expected, replacement);
        Err(crate::ClientError::illegal_argument(
            "conditional request-mode mutation is not implemented by this admin client",
        ))
    }

    /// Conditionally replaces one exact Topic/group request-mode entry using
    /// the caller's bounded request timeout.
    ///
    /// The default deliberately fails closed so existing trait implementers
    /// remain source compatible without silently ignoring the requested
    /// timeout.
    async fn replace_message_request_mode_if_current_with_timeout(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        expected: MutationExpectedMessageRequestMode,
        replacement: MutationMessageRequestMode,
        timeout_millis: u64,
    ) -> crate::ClientResult<MutationMessageRequestModeOutcome> {
        let _ = (
            broker_addr,
            topic,
            consumer_group,
            expected,
            replacement,
            timeout_millis,
        );
        Err(crate::ClientError::illegal_argument(
            "timeout-aware conditional request-mode mutation is not implemented by this admin client",
        ))
    }

    /// Applies one bounded Broker logger override with an automatic TTL.
    ///
    /// Implementations must reject arbitrary filter expressions. `logger`
    /// identifies one `rocketmq_broker::` target, `level` is limited to
    /// `INFO` or `DEBUG`, and the TTL is limited to the server-supported
    /// diagnostic window.
    async fn set_broker_log_filter_ttl(
        &self,
        broker_addr: CheetahString,
        logger: CheetahString,
        level: CheetahString,
        ttl_seconds: u32,
        operation_id: CheetahString,
    ) -> crate::ClientResult<()> {
        let _ = (broker_addr, logger, level, ttl_seconds, operation_id);
        Err(crate::ClientError::illegal_argument(
            "typed broker log-filter mutation is not implemented by this admin client",
        ))
    }

    /// Restores the Broker logger baseline for one bounded operation.
    async fn restore_broker_log_filter(
        &self,
        broker_addr: CheetahString,
        operation_id: CheetahString,
    ) -> crate::ClientResult<()> {
        let _ = (broker_addr, operation_id);
        Err(crate::ClientError::illegal_argument(
            "typed broker log-filter restoration is not implemented by this admin client",
        ))
    }

    async fn upsert_topic_config(&self, broker_addr: CheetahString, config: TopicConfig) -> crate::ClientResult<()>;

    async fn remove_topic(&self, topic_name: CheetahString, cluster_name: CheetahString) -> crate::ClientResult<()>;

    async fn reset_consumer_offset(
        &self,
        cluster_name: Option<CheetahString>,
        topic: CheetahString,
        consumer_group: CheetahString,
        timestamp: u64,
        force: bool,
    ) -> crate::ClientResult<HashMap<MessageQueue, u64>>;

    /// Resets each exact broker/queue target independently and retains partial outcomes.
    async fn reset_consumer_offset_detailed(
        &self,
        cluster_name: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        timestamp: u64,
        force: bool,
    ) -> crate::ClientResult<TopicOffsetMutationOutcome> {
        let _ = (cluster_name, topic, consumer_group, timestamp, force);
        Err(crate::ClientError::illegal_argument(
            "detailed reset-offset mutation is not implemented by this admin client",
        ))
    }

    /// Advances one exact consumer group and Topic to the latest available
    /// offsets. This is deliberately separate from timestamp reset because the
    /// RocketMQ protocol represents latest with the signed `-1` sentinel.
    async fn skip_accumulated_message(
        &self,
        cluster_name: Option<CheetahString>,
        topic: CheetahString,
        consumer_group: CheetahString,
        force: bool,
    ) -> crate::ClientResult<usize> {
        let _ = (cluster_name, topic, consumer_group, force);
        Err(crate::ClientError::illegal_argument(
            "skip-accumulated mutation is not implemented by this admin client",
        ))
    }

    /// Advances each exact broker/queue target to latest while retaining partial outcomes.
    async fn skip_accumulated_message_detailed(
        &self,
        cluster_name: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        force: bool,
    ) -> crate::ClientResult<TopicOffsetMutationOutcome> {
        let _ = (cluster_name, topic, consumer_group, force);
        Err(crate::ClientError::illegal_argument(
            "detailed skip-accumulated mutation is not implemented by this admin client",
        ))
    }

    async fn upsert_subscription_group(
        &self,
        broker_addr: CheetahString,
        config: SubscriptionGroupConfig,
    ) -> crate::ClientResult<()>;

    async fn remove_subscription_group(
        &self,
        broker_addr: CheetahString,
        group_name: CheetahString,
        remove_offset: Option<bool>,
    ) -> crate::ClientResult<()>;

    /// Removes multiple subscription groups from one broker in a single request.
    async fn remove_subscription_groups(
        &self,
        broker_addr: CheetahString,
        group_names: Vec<CheetahString>,
        clean_offset: bool,
    ) -> crate::ClientResult<()>;

    async fn configure_message_request_mode(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        mode: MessageRequestMode,
        pop_work_group_size: i32,
        timeout_millis: u64,
    ) -> crate::ClientResult<()>;

    async fn consume_directly(
        &self,
        consumer_group: CheetahString,
        client_id: CheetahString,
        topic: CheetahString,
        message_id: CheetahString,
    ) -> crate::ClientResult<ConsumeMessageDirectlyResult>;

    async fn clone_consumer_group_offset(
        &self,
        source_group: CheetahString,
        destination_group: CheetahString,
        topic: CheetahString,
        offline: bool,
    ) -> crate::ClientResult<()>;

    /// Returns the cluster topology needed to resolve mutation targets.
    async fn mutation_cluster_info(&self) -> crate::ClientResult<ClusterInfo>;

    /// Returns route data used to scope a mutation to the topic's brokers.
    async fn mutation_topic_route(&self, topic: CheetahString) -> crate::ClientResult<Option<TopicRouteData>>;

    /// Reads a broker's current topic configuration before a bounded test send.
    async fn mutation_topic_config(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
    ) -> crate::ClientResult<TopicConfig>;

    /// Removes a topic from an explicitly resolved broker set.
    async fn remove_topic_from_brokers(
        &self,
        broker_addrs: HashSet<CheetahString>,
        topic: CheetahString,
    ) -> crate::ClientResult<()>;

    /// Removes multiple topics from one broker in a single request.
    async fn remove_topics_from_broker(
        &self,
        broker_addr: CheetahString,
        topics: Vec<CheetahString>,
    ) -> crate::ClientResult<()>;

    /// Removes a topic from an explicitly resolved NameServer set.
    async fn remove_topic_from_name_servers(
        &self,
        namesrv_addrs: HashSet<CheetahString>,
        cluster_name: Option<CheetahString>,
        topic: CheetahString,
    ) -> crate::ClientResult<()>;

    /// Returns the NameServer targets owned by this started admin session.
    async fn mutation_name_server_addresses(&self) -> crate::ClientResult<Vec<CheetahString>>;

    /// Updates the order-topic configuration associated with a topic mutation.
    async fn upsert_order_topic_config(
        &self,
        topic: CheetahString,
        value: CheetahString,
        cluster_wide: bool,
    ) -> crate::ClientResult<()>;

    /// Reads the exact NameServer-wide order-topic value used by a supervised mutation guard.
    async fn mutation_order_topic_config(&self, topic: CheetahString) -> crate::ClientResult<Option<CheetahString>> {
        let _ = topic;
        Err(crate::ClientError::illegal_argument(
            "order Topic mutation preflight is not implemented by this admin client",
        ))
    }

    /// Deletes the global order-topic entry after an unordered update or a
    /// complete Topic deletion.
    async fn delete_order_topic_config(&self, topic: CheetahString) -> crate::ClientResult<()> {
        let _ = topic;
        Err(crate::ClientError::illegal_argument(
            "order Topic configuration deletion is not implemented by this admin client",
        ))
    }

    /// Performs the broker-by-broker offset reset fallback used for offline consumers.
    async fn reset_consumer_offset_legacy(
        &self,
        cluster_name: Option<CheetahString>,
        consumer_group: CheetahString,
        topic: CheetahString,
        timestamp: u64,
        force: bool,
    ) -> crate::ClientResult<Vec<RollbackStats>>;

    /// Views the message metadata required to validate a DLQ resend.
    async fn view_message_for_mutation(
        &self,
        topic: CheetahString,
        message_id: CheetahString,
    ) -> crate::ClientResult<MessageExt>;
}

impl MQAdminMutationExt for DefaultMQAdminExt {
    async fn begin_proxy_drain(
        &self,
        proxy_addr: CheetahString,
        operation_id: CheetahString,
    ) -> crate::ClientResult<ProxyDrainStateResponseBody> {
        MQAdminMutationExt::begin_proxy_drain(self.inner(), proxy_addr, operation_id).await
    }

    async fn cancel_proxy_drain(
        &self,
        proxy_addr: CheetahString,
        operation_id: CheetahString,
    ) -> crate::ClientResult<ProxyDrainStateResponseBody> {
        MQAdminMutationExt::cancel_proxy_drain(self.inner(), proxy_addr, operation_id).await
    }

    async fn broker_config_generation(&self, broker_addr: CheetahString) -> crate::ClientResult<u64> {
        MQAdminMutationExt::broker_config_generation(self.inner(), broker_addr).await
    }

    async fn patch_broker_config_if_generation(
        &self,
        broker_addr: CheetahString,
        expected_generation: u64,
        properties: HashMap<CheetahString, CheetahString>,
    ) -> crate::ClientResult<BrokerConfigPatchOutcome> {
        MQAdminMutationExt::patch_broker_config_if_generation(
            self.inner(),
            broker_addr,
            expected_generation,
            properties,
        )
        .await
    }

    async fn preview_consumer_offset_reset_on_broker(
        &self,
        broker_addr: CheetahString,
        broker_name: CheetahString,
        read_queue_nums: u32,
        consumer_group: CheetahString,
        topic: CheetahString,
        timestamp: i64,
    ) -> crate::ClientResult<Vec<MutationConsumerOffsetPreview>> {
        MQAdminMutationExt::preview_consumer_offset_reset_on_broker(
            self.inner(),
            broker_addr,
            broker_name,
            read_queue_nums,
            consumer_group,
            topic,
            timestamp,
        )
        .await
    }

    async fn mutation_consumer_offset(
        &self,
        broker_addr: CheetahString,
        consumer_group: CheetahString,
        topic: CheetahString,
        queue_id: i32,
    ) -> crate::ClientResult<i64> {
        MQAdminMutationExt::mutation_consumer_offset(self.inner(), broker_addr, consumer_group, topic, queue_id).await
    }

    async fn patch_topic_config_if_version(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        expected_version: u64,
        patch: TopicConfigPatch,
    ) -> crate::ClientResult<TopicConfigPatchOutcome> {
        MQAdminMutationExt::patch_topic_config_if_version(self.inner(), broker_addr, topic, expected_version, patch)
            .await
    }

    async fn mutation_topic_config_with_version(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
    ) -> crate::ClientResult<MutationTopicConfigVersioned> {
        MQAdminMutationExt::mutation_topic_config_with_version(self.inner(), broker_addr, topic).await
    }

    async fn mutation_topic_config_state(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
    ) -> crate::ClientResult<MutationTopicConfigState> {
        MQAdminMutationExt::mutation_topic_config_state(self.inner(), broker_addr, topic).await
    }

    async fn replace_topic_config_if_state(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        expected_state: MutationExpectedState,
        replacement: MutationTopicConfig,
    ) -> crate::ClientResult<MutationStateCasOutcome> {
        MQAdminMutationExt::replace_topic_config_if_state(self.inner(), broker_addr, topic, expected_state, replacement)
            .await
    }

    async fn patch_subscription_group_config_if_version(
        &self,
        broker_addr: CheetahString,
        group: CheetahString,
        expected_version: u64,
        patch: SubscriptionGroupConfigPatch,
    ) -> crate::ClientResult<SubscriptionGroupConfigPatchOutcome> {
        MQAdminMutationExt::patch_subscription_group_config_if_version(
            self.inner(),
            broker_addr,
            group,
            expected_version,
            patch,
        )
        .await
    }

    async fn mutation_subscription_group_config_state(
        &self,
        broker_addr: CheetahString,
        group: CheetahString,
    ) -> crate::ClientResult<MutationSubscriptionGroupConfigState> {
        MQAdminMutationExt::mutation_subscription_group_config_state(self.inner(), broker_addr, group).await
    }

    async fn replace_subscription_group_config_if_state(
        &self,
        broker_addr: CheetahString,
        group: CheetahString,
        expected_state: MutationExpectedState,
        replacement: MutationSubscriptionGroupConfig,
    ) -> crate::ClientResult<MutationStateCasOutcome> {
        MQAdminMutationExt::replace_subscription_group_config_if_state(
            self.inner(),
            broker_addr,
            group,
            expected_state,
            replacement,
        )
        .await
    }

    async fn broker_mutation_config_state(
        &self,
        broker_addr: CheetahString,
    ) -> crate::ClientResult<BrokerMutationConfigState> {
        MQAdminMutationExt::broker_mutation_config_state(self.inner(), broker_addr).await
    }

    async fn reset_consumer_offset_if_current(
        &self,
        broker_addr: CheetahString,
        consumer_group: CheetahString,
        topic: CheetahString,
        queue_id: i32,
        expected_offset: i64,
        new_offset: i64,
    ) -> crate::ClientResult<ConditionalConsumerOffsetOutcome> {
        MQAdminMutationExt::reset_consumer_offset_if_current(
            self.inner(),
            broker_addr,
            consumer_group,
            topic,
            queue_id,
            expected_offset,
            new_offset,
        )
        .await
    }

    async fn mutation_message_request_mode(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
    ) -> crate::ClientResult<Option<MutationMessageRequestMode>> {
        MQAdminMutationExt::mutation_message_request_mode(self.inner(), broker_addr, topic, consumer_group).await
    }

    async fn replace_message_request_mode_if_current(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        expected: MutationExpectedMessageRequestMode,
        replacement: MutationMessageRequestMode,
    ) -> crate::ClientResult<MutationMessageRequestModeOutcome> {
        MQAdminMutationExt::replace_message_request_mode_if_current(
            self.inner(),
            broker_addr,
            topic,
            consumer_group,
            expected,
            replacement,
        )
        .await
    }

    async fn replace_message_request_mode_if_current_with_timeout(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        expected: MutationExpectedMessageRequestMode,
        replacement: MutationMessageRequestMode,
        timeout_millis: u64,
    ) -> crate::ClientResult<MutationMessageRequestModeOutcome> {
        MQAdminMutationExt::replace_message_request_mode_if_current_with_timeout(
            self.inner(),
            broker_addr,
            topic,
            consumer_group,
            expected,
            replacement,
            timeout_millis,
        )
        .await
    }

    async fn set_broker_log_filter_ttl(
        &self,
        broker_addr: CheetahString,
        logger: CheetahString,
        level: CheetahString,
        ttl_seconds: u32,
        operation_id: CheetahString,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::set_broker_log_filter_ttl(
            self.inner(),
            broker_addr,
            logger,
            level,
            ttl_seconds,
            operation_id,
        )
        .await
    }

    async fn restore_broker_log_filter(
        &self,
        broker_addr: CheetahString,
        operation_id: CheetahString,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::restore_broker_log_filter(self.inner(), broker_addr, operation_id).await
    }

    async fn upsert_topic_config(&self, broker_addr: CheetahString, config: TopicConfig) -> crate::ClientResult<()> {
        MQAdminMutationExt::upsert_topic_config(self.inner(), broker_addr, config).await
    }

    async fn remove_topic(&self, topic_name: CheetahString, cluster_name: CheetahString) -> crate::ClientResult<()> {
        MQAdminMutationExt::remove_topic(self.inner(), topic_name, cluster_name).await
    }

    async fn reset_consumer_offset(
        &self,
        cluster_name: Option<CheetahString>,
        topic: CheetahString,
        consumer_group: CheetahString,
        timestamp: u64,
        force: bool,
    ) -> crate::ClientResult<HashMap<MessageQueue, u64>> {
        MQAdminMutationExt::reset_consumer_offset(self.inner(), cluster_name, topic, consumer_group, timestamp, force)
            .await
    }

    async fn reset_consumer_offset_detailed(
        &self,
        cluster_name: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        timestamp: u64,
        force: bool,
    ) -> crate::ClientResult<TopicOffsetMutationOutcome> {
        MQAdminMutationExt::reset_consumer_offset_detailed(
            self.inner(),
            cluster_name,
            topic,
            consumer_group,
            timestamp,
            force,
        )
        .await
    }

    async fn skip_accumulated_message(
        &self,
        cluster_name: Option<CheetahString>,
        topic: CheetahString,
        consumer_group: CheetahString,
        force: bool,
    ) -> crate::ClientResult<usize> {
        MQAdminMutationExt::skip_accumulated_message(self.inner(), cluster_name, topic, consumer_group, force).await
    }

    async fn skip_accumulated_message_detailed(
        &self,
        cluster_name: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        force: bool,
    ) -> crate::ClientResult<TopicOffsetMutationOutcome> {
        MQAdminMutationExt::skip_accumulated_message_detailed(self.inner(), cluster_name, topic, consumer_group, force)
            .await
    }

    async fn upsert_subscription_group(
        &self,
        broker_addr: CheetahString,
        config: SubscriptionGroupConfig,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::upsert_subscription_group(self.inner(), broker_addr, config).await
    }

    async fn remove_subscription_group(
        &self,
        broker_addr: CheetahString,
        group_name: CheetahString,
        remove_offset: Option<bool>,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::remove_subscription_group(self.inner(), broker_addr, group_name, remove_offset).await
    }

    async fn remove_subscription_groups(
        &self,
        broker_addr: CheetahString,
        group_names: Vec<CheetahString>,
        clean_offset: bool,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::remove_subscription_groups(self.inner(), broker_addr, group_names, clean_offset).await
    }

    async fn configure_message_request_mode(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
        consumer_group: CheetahString,
        mode: MessageRequestMode,
        pop_work_group_size: i32,
        timeout_millis: u64,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::configure_message_request_mode(
            self.inner(),
            broker_addr,
            topic,
            consumer_group,
            mode,
            pop_work_group_size,
            timeout_millis,
        )
        .await
    }

    async fn consume_directly(
        &self,
        consumer_group: CheetahString,
        client_id: CheetahString,
        topic: CheetahString,
        message_id: CheetahString,
    ) -> crate::ClientResult<ConsumeMessageDirectlyResult> {
        MQAdminMutationExt::consume_directly(self.inner(), consumer_group, client_id, topic, message_id).await
    }

    async fn clone_consumer_group_offset(
        &self,
        source_group: CheetahString,
        destination_group: CheetahString,
        topic: CheetahString,
        offline: bool,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::clone_consumer_group_offset(self.inner(), source_group, destination_group, topic, offline)
            .await
    }

    async fn mutation_cluster_info(&self) -> crate::ClientResult<ClusterInfo> {
        MQAdminMutationExt::mutation_cluster_info(self.inner()).await
    }

    async fn mutation_topic_route(&self, topic: CheetahString) -> crate::ClientResult<Option<TopicRouteData>> {
        MQAdminMutationExt::mutation_topic_route(self.inner(), topic).await
    }

    async fn mutation_topic_config(
        &self,
        broker_addr: CheetahString,
        topic: CheetahString,
    ) -> crate::ClientResult<TopicConfig> {
        MQAdminMutationExt::mutation_topic_config(self.inner(), broker_addr, topic).await
    }

    async fn remove_topic_from_brokers(
        &self,
        broker_addrs: HashSet<CheetahString>,
        topic: CheetahString,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::remove_topic_from_brokers(self.inner(), broker_addrs, topic).await
    }

    async fn remove_topics_from_broker(
        &self,
        broker_addr: CheetahString,
        topics: Vec<CheetahString>,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::remove_topics_from_broker(self.inner(), broker_addr, topics).await
    }

    async fn remove_topic_from_name_servers(
        &self,
        namesrv_addrs: HashSet<CheetahString>,
        cluster_name: Option<CheetahString>,
        topic: CheetahString,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::remove_topic_from_name_servers(self.inner(), namesrv_addrs, cluster_name, topic).await
    }

    async fn mutation_name_server_addresses(&self) -> crate::ClientResult<Vec<CheetahString>> {
        MQAdminMutationExt::mutation_name_server_addresses(self.inner()).await
    }

    async fn upsert_order_topic_config(
        &self,
        topic: CheetahString,
        value: CheetahString,
        cluster_wide: bool,
    ) -> crate::ClientResult<()> {
        MQAdminMutationExt::upsert_order_topic_config(self.inner(), topic, value, cluster_wide).await
    }

    async fn mutation_order_topic_config(&self, topic: CheetahString) -> crate::ClientResult<Option<CheetahString>> {
        MQAdminMutationExt::mutation_order_topic_config(self.inner(), topic).await
    }

    async fn delete_order_topic_config(&self, topic: CheetahString) -> crate::ClientResult<()> {
        MQAdminMutationExt::delete_order_topic_config(self.inner(), topic).await
    }

    async fn reset_consumer_offset_legacy(
        &self,
        cluster_name: Option<CheetahString>,
        consumer_group: CheetahString,
        topic: CheetahString,
        timestamp: u64,
        force: bool,
    ) -> crate::ClientResult<Vec<RollbackStats>> {
        MQAdminMutationExt::reset_consumer_offset_legacy(
            self.inner(),
            cluster_name,
            consumer_group,
            topic,
            timestamp,
            force,
        )
        .await
    }

    async fn view_message_for_mutation(
        &self,
        topic: CheetahString,
        message_id: CheetahString,
    ) -> crate::ClientResult<MessageExt> {
        MQAdminMutationExt::view_message_for_mutation(self.inner(), topic, message_id).await
    }
}