Skip to main content

rocketmq_client_rust/admin/
mq_admin_topic_stats_read_ext.rs

1// Copyright 2026 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
15//! Exact-Broker, read-only Topic statistics capability.
16
17use cheetah_string::CheetahString;
18use rocketmq_protocol::protocol::admin::topic_stats_table::TopicStatsTable;
19use rocketmq_protocol::protocol::header::get_topic_stats_info_request_header::GetTopicStatsInfoRequestHeader;
20
21use super::default_mq_admin_ext::DefaultMQAdminExt;
22
23/// Additive capability for reading Topic statistics from one already resolved
24/// Broker target. Address resolution remains the responsibility of a trusted
25/// adapter and addresses never cross this trait's result boundary.
26#[allow(async_fn_in_trait)]
27pub trait MQAdminTopicStatsReadExt: Send {
28    /// Reads the Topic statistics exposed by one exact Broker.
29    async fn topic_stats_at(
30        &self,
31        broker_addr: CheetahString,
32        topic: CheetahString,
33    ) -> crate::ClientResult<TopicStatsTable>;
34}
35
36impl MQAdminTopicStatsReadExt for DefaultMQAdminExt {
37    async fn topic_stats_at(
38        &self,
39        broker_addr: CheetahString,
40        topic: CheetahString,
41    ) -> crate::ClientResult<TopicStatsTable> {
42        self.inner()
43            .mq_client_api()?
44            .get_topic_stats_info(
45                &broker_addr,
46                GetTopicStatsInfoRequestHeader {
47                    topic,
48                    topic_request_header: None,
49                },
50                self.inner().remoting_timeout_millis()?,
51            )
52            .await
53    }
54}