rocketmq_controller/processor/
request.rs1use std::net::SocketAddr;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use crate::metadata::BrokerInfo;
24use crate::metadata::BrokerRole;
25use crate::metadata::TopicInfo;
26
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
29pub enum RequestType {
30 RegisterBroker,
31 UnregisterBroker,
32 BrokerHeartbeat,
33 ElectMaster,
34 GetMetadata,
35 CreateTopic,
36 UpdateTopic,
37 DeleteTopic,
38 UpdateConfig,
39 GetConfig,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct RegisterBrokerRequest {
45 pub broker_name: String,
47
48 pub broker_id: u64,
50
51 pub cluster_name: String,
53
54 pub broker_addr: SocketAddr,
56
57 pub version: String,
59
60 pub role: BrokerRole,
62
63 pub metadata: serde_json::Value,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct RegisterBrokerResponse {
70 pub success: bool,
72
73 pub error: Option<String>,
75
76 pub broker_id: Option<u64>,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct UnregisterBrokerRequest {
83 pub broker_name: String,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct UnregisterBrokerResponse {
90 pub success: bool,
92
93 pub error: Option<String>,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct BrokerHeartbeatRequest {
100 pub broker_name: String,
102
103 pub timestamp: u64,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct BrokerHeartbeatResponse {
110 pub success: bool,
112
113 pub error: Option<String>,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct ElectMasterRequest {
120 pub cluster_name: String,
122
123 pub broker_name: String,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129pub struct ElectMasterResponse {
130 pub success: bool,
132
133 pub error: Option<String>,
135
136 pub master_broker: Option<String>,
138
139 pub master_addr: Option<SocketAddr>,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
145pub struct GetMetadataRequest {
146 pub metadata_type: MetadataType,
148
149 pub key: Option<String>,
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
155pub enum MetadataType {
156 Broker,
157 Topic,
158 Config,
159 All,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct GetMetadataResponse {
165 pub success: bool,
167
168 pub error: Option<String>,
170
171 pub brokers: Vec<BrokerInfo>,
173
174 pub topics: Vec<TopicInfo>,
176
177 pub configs: serde_json::Value,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct CreateTopicRequest {
184 pub topic_name: String,
186
187 pub read_queue_nums: u32,
189
190 pub write_queue_nums: u32,
192
193 pub perm: u32,
195
196 pub topic_sys_flag: u32,
198}
199
200#[derive(Debug, Clone, Serialize, Deserialize)]
202pub struct CreateTopicResponse {
203 pub success: bool,
205
206 pub error: Option<String>,
208}
209
210#[derive(Debug, Clone, Serialize, Deserialize)]
212pub struct UpdateTopicRequest {
213 pub topic_name: String,
215
216 pub topic_info: TopicInfo,
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
222pub struct UpdateTopicResponse {
223 pub success: bool,
225
226 pub error: Option<String>,
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct DeleteTopicRequest {
233 pub topic_name: String,
235}
236
237#[derive(Debug, Clone, Serialize, Deserialize)]
239pub struct DeleteTopicResponse {
240 pub success: bool,
242
243 pub error: Option<String>,
245}
246
247#[cfg(test)]
248mod tests {
249 use super::*;
250
251 #[test]
252 fn test_request_serialization() {
253 let req = RegisterBrokerRequest {
254 broker_name: "broker-a".to_string(),
255 broker_id: 0,
256 cluster_name: "DefaultCluster".to_string(),
257 broker_addr: "127.0.0.1:10911".parse().unwrap(),
258 version: "5.0.0".to_string(),
259 role: BrokerRole::Master,
260 metadata: serde_json::json!({}),
261 };
262
263 let json = serde_json::to_string(&req).unwrap();
264 let deserialized: RegisterBrokerRequest = serde_json::from_str(&json).unwrap();
265 assert_eq!(req.broker_name, deserialized.broker_name);
266 }
267}