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
85
86
87
88
89
90
91
// 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::{commons::PaginationParams, path, responses};
use super::client::{Client, Result};
use std::fmt::Display;
impl<E, U, P> Client<E, U, P>
where
E: Display,
U: Display,
P: Display,
{
/// Lists all channels across the cluster.
/// See [Channels Guide](https://www.rabbitmq.com/docs/channels) to learn more.
///
/// Requires the `management` user tag. Does not modify state.
pub fn list_channels(&self) -> Result<Vec<responses::Channel>> {
self.get_api_request("channels")
}
/// Lists channels with pagination.
///
/// Requires the `management` user tag. Does not modify state.
pub fn list_channels_paged(
&self,
params: &PaginationParams,
) -> Result<Vec<responses::Channel>> {
match params.to_query_string() {
Some(query) => self.get_paginated_api_request("channels", &query),
None => self.list_channels(),
}
}
/// Lists all channels in the given virtual host.
/// See [Channels Guide](https://www.rabbitmq.com/docs/channels) to learn more.
///
/// Requires the `management` user tag. Does not modify state.
pub fn list_channels_in(&self, virtual_host: &str) -> Result<Vec<responses::Channel>> {
self.get_api_request(path!("vhosts", virtual_host, "channels"))
}
/// Lists channels in the given virtual host with pagination.
///
/// Requires the `management` user tag. Does not modify state.
pub fn list_channels_in_paged(
&self,
virtual_host: &str,
params: &PaginationParams,
) -> Result<Vec<responses::Channel>> {
match params.to_query_string() {
Some(query) => {
self.get_paginated_api_request(path!("vhosts", virtual_host, "channels"), &query)
}
None => self.list_channels_in(virtual_host),
}
}
/// Lists all channels on a given AMQP 0-9-1 connection.
/// See [Channels Guide](https://www.rabbitmq.com/docs/channels) to learn more.
///
/// Requires the `management` user tag. Does not modify state.
pub fn list_channels_on(&self, connection_name: &str) -> Result<Vec<responses::Channel>> {
self.get_api_request(path!("connections", connection_name, "channels"))
}
/// Returns information about a specific channel.
///
/// Unlike AMQP 0-9-1, HTTP API identifies channels by a string identifier instead of a numeric ID.
///
/// Channel name is usually obtained from `crate::responses::Channel`,
/// e.g. via `Client#list_channels`, `Client#list_channels_in`, `Client#list_channels_on`.
/// See [Channels Guide](https://www.rabbitmq.com/docs/channels) to learn more.
///
/// Requires the `management` user tag. Does not modify state.
pub fn get_channel_info<S: AsRef<str>>(&self, channel_name: S) -> Result<responses::Channel> {
self.get_api_request(path!("channels", channel_name.as_ref()))
}
}