Skip to main content

rocketmq_protocol/protocol/header/
remove_broker_request_header.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
15use cheetah_string::CheetahString;
16use rocketmq_macros::RequestHeaderCodec;
17use serde::Deserialize;
18use serde::Serialize;
19
20#[derive(Clone, Debug, Default, Serialize, Deserialize, RequestHeaderCodec)]
21#[serde(rename_all = "camelCase")]
22#[header(
23    type_id = "rocketmq_protocol::protocol::header::remove_broker_request_header::RemoveBrokerRequestHeader",
24    java_class = "org.apache.rocketmq.remoting.protocol.header.RemoveBrokerRequestHeader"
25)]
26pub struct RemoveBrokerRequestHeader {
27    #[header(required)]
28    pub broker_name: CheetahString,
29    #[header(required)]
30    pub broker_cluster_name: CheetahString,
31    #[header(required, range = "i64")]
32    pub broker_id: u64,
33}
34
35#[cfg(test)]
36mod tests {
37    use std::collections::HashMap;
38
39    use super::*;
40    use crate::protocol::command_custom_header::CommandCustomHeader;
41    use crate::protocol::command_custom_header::FromMap;
42
43    #[test]
44    fn remove_broker_request_header_serializes_broker_identity() {
45        let header = RemoveBrokerRequestHeader {
46            broker_name: CheetahString::from_static_str("broker-a"),
47            broker_cluster_name: CheetahString::from_static_str("DefaultCluster"),
48            broker_id: 1,
49        };
50
51        let map = header.to_map().expect("header should encode");
52        assert_eq!(
53            map.get(&CheetahString::from_static_str("brokerName")),
54            Some(&CheetahString::from_static_str("broker-a"))
55        );
56        assert_eq!(
57            map.get(&CheetahString::from_static_str("brokerClusterName")),
58            Some(&CheetahString::from_static_str("DefaultCluster"))
59        );
60        assert_eq!(
61            map.get(&CheetahString::from_static_str("brokerId")),
62            Some(&CheetahString::from_static_str("1"))
63        );
64    }
65
66    #[test]
67    fn remove_broker_request_header_deserializes_broker_identity() {
68        let mut map = HashMap::new();
69        map.insert(
70            CheetahString::from_static_str("brokerName"),
71            CheetahString::from_static_str("broker-a"),
72        );
73        map.insert(
74            CheetahString::from_static_str("brokerClusterName"),
75            CheetahString::from_static_str("DefaultCluster"),
76        );
77        map.insert(
78            CheetahString::from_static_str("brokerId"),
79            CheetahString::from_static_str("1"),
80        );
81
82        let header = <RemoveBrokerRequestHeader as FromMap>::from(&map).expect("header should decode");
83        assert_eq!(header.broker_name, CheetahString::from_static_str("broker-a"));
84        assert_eq!(
85            header.broker_cluster_name,
86            CheetahString::from_static_str("DefaultCluster")
87        );
88        assert_eq!(header.broker_id, 1);
89    }
90}