Skip to content

Commit 5c0f88b

Browse files
Initial federation link types
1 parent f3702af commit 5c0f88b

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

src/responses.rs

+43
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,49 @@ impl TryFrom<RuntimeParameter> for FederationUpstream {
20462046
}
20472047
}
20482048

2049+
#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Default)]
2050+
#[serde(rename_all = "lowercase")]
2051+
pub enum FederationType {
2052+
#[default]
2053+
Exchange,
2054+
Queue,
2055+
}
2056+
2057+
impl fmt::Display for FederationType {
2058+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2059+
match self {
2060+
FederationType::Exchange => write!(f, "exchange"),
2061+
FederationType::Queue => write!(f, "queue"),
2062+
}
2063+
}
2064+
}
2065+
2066+
impl From<String> for FederationType {
2067+
fn from(value: String) -> Self {
2068+
match value.as_str() {
2069+
"exchange" => FederationType::Exchange,
2070+
"queue" => FederationType::Queue,
2071+
_ => FederationType::default(),
2072+
}
2073+
}
2074+
}
2075+
2076+
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
2077+
#[cfg_attr(feature = "tabled", derive(Tabled))]
2078+
#[allow(dead_code)]
2079+
pub struct FederationLink {
2080+
pub node: String,
2081+
pub vhost: String,
2082+
pub id: String,
2083+
pub uri: String,
2084+
pub status: String,
2085+
#[serde(rename = "type")]
2086+
pub typ: FederationType,
2087+
pub upstream: String,
2088+
#[cfg_attr(feature = "tabled", tabled(display = "display_option"))]
2089+
pub consumer_tag: Option<String>,
2090+
}
2091+
20492092
//
20502093
// Shovels
20512094
//

tests/unit_federation_conversion_tests.rs

+63-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod test_helpers;
1515

1616
use rabbitmq_http_client::{
1717
commons::MessageTransferAcknowledgementMode,
18-
responses::{FederationUpstream, RuntimeParameter},
18+
responses::{FederationLink, FederationType, FederationUpstream, RuntimeParameter},
1919
};
2020

2121
#[test]
@@ -86,3 +86,65 @@ fn test_unit_deserialize_federation_upstream_case2() {
8686
upstream.ack_mode
8787
);
8888
}
89+
90+
#[test]
91+
fn test_unit_deserialize_federation_link_case1() {
92+
let json = r#"
93+
{
94+
"node": "rabbit@sunnyside",
95+
"queue": "fed.cq.1",
96+
"upstream_queue": "fed.cq.overridden",
97+
"consumer_tag": "hgksdh98s7f98au9u",
98+
"type": "queue",
99+
"vhost": "/",
100+
"upstream": "up-1",
101+
"id": "e178dfad",
102+
"status": "running",
103+
"local_connection": "<[email protected]>",
104+
"uri": "amqp://localhost:5672/fed",
105+
"timestamp": "2025-03-16 0:41:29",
106+
"local_channel": {
107+
"acks_uncommitted": 0,
108+
"confirm": true,
109+
"connection_details": {
110+
"name": "<[email protected]>",
111+
"peer_host": "undefined",
112+
"peer_port": "undefined"
113+
},
114+
"consumer_count": 0,
115+
"garbage_collection": {
116+
"fullsweep_after": 65535,
117+
"max_heap_size": 0,
118+
"min_bin_vheap_size": 1727361,
119+
"min_heap_size": 233,
120+
"minor_gcs": 6
121+
},
122+
"idle_since": "2025-03-16T00:41:30.097-04:00",
123+
"messages_unacknowledged": 0,
124+
"messages_uncommitted": 0,
125+
"messages_unconfirmed": 0,
126+
"name": "<[email protected]> (1)",
127+
"node": "rabbit@sunnyside",
128+
"number": 1,
129+
"pending_raft_commands": 0,
130+
"prefetch_count": 0,
131+
"reductions": 1127,
132+
"reductions_details": {
133+
"rate": 0.0
134+
},
135+
"state": "running",
136+
"transactional": false,
137+
"user": "none",
138+
"user_who_performed_action": "none",
139+
"vhost": "/"
140+
}
141+
}
142+
"#;
143+
144+
let link: FederationLink = serde_json::from_str(&json).unwrap();
145+
assert_eq!(link.uri, "amqp://localhost:5672/fed");
146+
assert_eq!(link.id, "e178dfad");
147+
assert_eq!(link.typ, FederationType::Queue);
148+
assert_eq!(link.upstream, "up-1");
149+
assert_eq!(link.consumer_tag.unwrap(), "hgksdh98s7f98au9u");
150+
}

0 commit comments

Comments
 (0)