1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) 2023-2025 RabbitMQ Core Team (teamrabbitmq@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::requests::RuntimeParameterDefinition;
use crate::requests::federation::{FEDERATION_UPSTREAM_COMPONENT, FederationUpstreamParams};
use crate::responses::{FederationLink, FederationUpstream};
use super::client::{Client, Result};
use std::fmt::Display;
use std::result::Result as StdResult;
impl<E, U, P> Client<E, U, P>
where
E: Display,
U: Display,
P: Display,
{
/// Lists [federation](https://www.rabbitmq.com/docs/federation) upstreams defined in the cluster.
///
/// Requires the `policymaker` user tag. Does not modify state.
pub fn list_federation_upstreams(&self) -> Result<Vec<FederationUpstream>> {
let response = self.list_runtime_parameters_of_component(FEDERATION_UPSTREAM_COMPONENT)?;
let upstreams = response
.into_iter()
.map(FederationUpstream::try_from)
.collect::<StdResult<Vec<_>, _>>()?;
Ok(upstreams)
}
/// Lists [federation](https://www.rabbitmq.com/docs/federation) links (connections) running in the cluster.
///
/// Requires the `monitoring` user tag. Does not modify state.
/// Can be used by restricted monitoring users with the `monitoring` tag and only the `read`, `configure` permissions.
pub fn list_federation_links(&self) -> Result<Vec<FederationLink>> {
let response = self.http_get("federation-links", None, None)?;
let response = response.json()?;
Ok(response)
}
/// Creates or updates a [federation](https://www.rabbitmq.com/docs/federation) upstream.
///
/// Federation upstreams define connection endpoints for federation links (connections that federate
/// queues or exchanges).
///
/// Requires the `policymaker` user tag.
pub fn declare_federation_upstream(&self, params: FederationUpstreamParams<'_>) -> Result<()> {
let runtime_param = RuntimeParameterDefinition::from(params);
self.upsert_runtime_parameter(&runtime_param)
}
/// Gets a specific [federation](https://www.rabbitmq.com/docs/federation) upstream by name and virtual host.
///
/// Requires the `policymaker` user tag. Does not modify state.
pub fn get_federation_upstream(&self, vhost: &str, name: &str) -> Result<FederationUpstream> {
let param = self.get_runtime_parameter(FEDERATION_UPSTREAM_COMPONENT, vhost, name)?;
FederationUpstream::try_from(param).map_err(|e| e.into())
}
/// Deletes a [federation](https://www.rabbitmq.com/docs/federation) upstream.
/// Deleting an upstream will stop any links connected to it.
///
/// Requires the `policymaker` user tag.
pub fn delete_federation_upstream(
&self,
vhost: &str,
name: &str,
idempotently: bool,
) -> Result<()> {
self.clear_runtime_parameter(FEDERATION_UPSTREAM_COMPONENT, vhost, name, idempotently)
}
}