Skip to content

Commit 820c0e2

Browse files
authored
[ISSUE #76] ✨ Namesrv supports get all topic list from name server(request code 206) (#81)
1 parent d8ec4f5 commit 820c0e2

File tree

7 files changed

+96
-18
lines changed

7 files changed

+96
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Feature list:
9595
| Get broker cluster info | 106 | :sparkling_heart: :white_check_mark: | |
9696
| Wipe write perm of boker | 205 | :sparkling_heart: :white_check_mark: | |
9797
| Add write perm of brober | 327 | :sparkling_heart: :white_check_mark: | |
98-
| Get all topic list from name server | 206 | :broken_heart: :x: | |
98+
| Get all topic list from name server | 206 | :sparkling_heart: :white_check_mark: | |
9999
| Delete topic in name server | 216 | :broken_heart: :x: | |
100100
| Register topic in name server | 217 | :broken_heart: :x: | |
101101
| Get topics by cluster | 224 | :broken_heart: :x: | |

rocketmq-namesrv/README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ Feature list:
1414

1515
- **Perfect support**: :sparkling_heart: :white_check_mark:
1616

17-
| Feature | request code | Support | remark |
18-
| -------------------------------------- | ------------ | -------------- | ------ |
19-
| Put KV Config | 100 | :sparkling_heart: :white_check_mark: | |
17+
| Feature | request code | Support | remark |
18+
| -------------------------------------- | ------------ |--------------------------------------|--------|
19+
| Put KV Config | 100 | :sparkling_heart: :white_check_mark: | |
2020
| Get KV Config | 101 | :sparkling_heart: :white_check_mark: | |
2121
| Delete KV Config | 102 | :sparkling_heart: :white_check_mark: | |
22-
| Get kv list by namespace | 219 | :broken_heart: :x: | |
23-
| Query Data Version | 322 | :sparkling_heart: :white_check_mark:| |
24-
| Register Broker | 103 | :heart: :white_check_mark: | |
25-
| Unregister Broker | 104 | :broken_heart: :x: | |
22+
| Get kv list by namespace | 219 | :broken_heart: :x: | |
23+
| Query Data Version | 322 | :sparkling_heart: :white_check_mark: | |
24+
| Register Broker | 103 | :heart: :white_check_mark: | |
25+
| Unregister Broker | 104 | :broken_heart: :x: | |
2626
| Broker Heartbeat | 904 | :sparkling_heart: :white_check_mark: | |
2727
| Get broker member_group | 901 | :sparkling_heart: :white_check_mark: | |
2828
| Get broker cluster info | 106 | :sparkling_heart: :white_check_mark: | |
2929
| Wipe write perm of boker | 205 | :sparkling_heart: :white_check_mark: | |
3030
| Add write perm of brober | 327 | :sparkling_heart: :white_check_mark: | |
31-
| Get all topic list from name server | 206 | :broken_heart: :x: | |
32-
| Delete topic in name server | 216 | :broken_heart: :x: | |
33-
| Register topic in name server | 217 | :broken_heart: :x: | |
34-
| Get topics by cluster | 224 | :broken_heart: :x: | |
35-
| Get system topic list from name server | 304 | :broken_heart: :x: | |
36-
| Get unit topic list | 311 | :broken_heart: :x: | |
37-
| Get has unit sub topic list | 312 | :broken_heart: :x: | |
38-
| Get has unit sub ununit topic list | 313 | :broken_heart: :x: | |
39-
| Update name server config | 318 | :broken_heart: :x: | |
40-
| Get name server config | 318 | :broken_heart: :x: | |
31+
| Get all topic list from name server | 206 | :sparkling_heart: :white_check_mark: | |
32+
| Delete topic in name server | 216 | :broken_heart: :x: | |
33+
| Register topic in name server | 217 | :broken_heart: :x: | |
34+
| Get topics by cluster | 224 | :broken_heart: :x: | |
35+
| Get system topic list from name server | 304 | :broken_heart: :x: | |
36+
| Get unit topic list | 311 | :broken_heart: :x: | |
37+
| Get has unit sub topic list | 312 | :broken_heart: :x: | |
38+
| Get has unit sub ununit topic list | 313 | :broken_heart: :x: | |
39+
| Update name server config | 318 | :broken_heart: :x: | |
40+
| Get name server config | 318 | :broken_heart: :x: | |
4141

4242
## Getting Started
4343

rocketmq-namesrv/src/processor/default_request_processor.rs

+15
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ impl RequestProcessor for DefaultRequestProcessor {
8383
Some(RequestCode::GetBrokerClusterInfo) => self.get_broker_cluster_info(request),
8484
Some(RequestCode::WipeWritePermOfBroker) => self.wipe_write_perm_of_broker(request),
8585
Some(RequestCode::AddWritePermOfBroker) => self.add_write_perm_of_broker(request),
86+
Some(RequestCode::GetAllTopicListFromNameserver) => {
87+
self.get_all_topic_list_from_nameserver(request)
88+
}
8689

8790
_ => RemotingCommand::create_response_command_with_code(
8891
RemotingSysResponseCode::SystemError,
@@ -348,6 +351,18 @@ impl DefaultRequestProcessor {
348351
AddWritePermOfBrokerResponseHeader::new(add_topic_cnt),
349352
)))
350353
}
354+
355+
fn get_all_topic_list_from_nameserver(&mut self, _request: RemotingCommand) -> RemotingCommand {
356+
let rd_lock = self.route_info_manager.read();
357+
if rd_lock.namesrv_config.enable_all_topic_list {
358+
let topics = rd_lock.get_all_topic_list();
359+
drop(rd_lock); //release lock
360+
return RemotingCommand::create_response_command()
361+
.set_body(Some(Bytes::from(topics.encode())));
362+
}
363+
RemotingCommand::create_response_command_with_code(RemotingSysResponseCode::SystemError)
364+
.set_remark(Some(String::from("disable")))
365+
}
351366
}
352367

353368
fn extract_register_topic_config_from_request(

rocketmq-namesrv/src/route/route_info_manager.rs

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rocketmq_remoting::{
3333
protocol::{
3434
body::{
3535
broker_body::{broker_member_group::BrokerMemberGroup, cluster_info::ClusterInfo},
36+
topic::topic_list::TopicList,
3637
topic_info_wrapper::topic_config_wrapper::TopicConfigAndMappingSerializeWrapper,
3738
},
3839
header::namesrv::brokerid_change_request_header::NotifyMinBrokerIdChangeRequestHeader,
@@ -675,4 +676,17 @@ impl RouteInfoManager {
675676
}
676677
topic_cnt
677678
}
679+
680+
pub(crate) fn get_all_topic_list(&self) -> TopicList {
681+
let topics = self
682+
.topic_queue_table
683+
.keys()
684+
.cloned()
685+
.collect::<Vec<String>>();
686+
687+
TopicList {
688+
topic_list: topics,
689+
broker_addr: None,
690+
}
691+
}
678692
}

rocketmq-remoting/src/protocol/body.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717

1818
pub mod broker_body;
1919
pub mod kv_table;
20+
pub mod topic;
2021
pub mod topic_info_wrapper;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
*/
17+
18+
pub mod topic_list;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
*/
17+
use serde::{Deserialize, Serialize};
18+
19+
use crate::protocol::RemotingSerializable;
20+
21+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
22+
#[serde(rename_all = "camelCase")]
23+
pub struct TopicList {
24+
pub topic_list: Vec<String>,
25+
pub broker_addr: Option<String>,
26+
}
27+
28+
impl RemotingSerializable for TopicList {
29+
type Output = TopicList;
30+
}

0 commit comments

Comments
 (0)