Skip to content

Commit 67be6ae

Browse files
Implement Client#get_channel_info
1 parent b65a1b6 commit 67be6ae

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
### Enhancements
66

7-
* `Client#current_user` is a new function providing support for the `GET /api/whoami` endpoint.
87
* `Client#auth_attempts_statistics` is a new function providing support for the `GET /api/auth/attempts/{node}` endpoint.
98
* `Client#list_topic_permissions` is a new function that provides support for the `GET /api/topic-permissions` endpoint.
109
* `Client#list_topic_permissions_in` is a new function that provides support for the `GET /api/vhosts/{vhost}/topic-permissions` endpoint.
1110
* `Client#get_topic_permissions_of` is a new function that provides support for the `GET /api/topic-permissions/{vhost}/{user}` endpoint.
1211
* `Client#list_channels_on` is a new function that provides support for the `GET /api/connections/{connection}/channels` endpoint.
13-
12+
* `Client#get_channel_info` returns information about a specific channel.
13+
* `Client#current_user` is a new function providing support for the `GET /api/whoami` endpoint.
1414

1515
## v0.50.0 (Sep 13, 2025)
1616

src/api.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use crate::responses::{
2626
WarmStandbyReplicationStatus,
2727
};
2828
use crate::{
29-
commons::{BindingDestinationType, SupportedProtocol, UserLimitTarget, VirtualHostLimitTarget},
29+
commons::{
30+
BindingDestinationType, SupportedProtocol, UserLimitTarget,
31+
VirtualHostLimitTarget,
32+
},
3033
path,
3134
requests::{
3235
self, BulkUserDelete, EnforcedLimitParams, ExchangeParams, Permissions, PolicyParams,
@@ -412,6 +415,18 @@ where
412415
.await
413416
}
414417

418+
/// Returns information about a specific channel.
419+
///
420+
/// Unlike AMQP 0-9-1, HTTP API identifies channels by a string identifier instead of a numeric ID.
421+
///
422+
/// Channel name is usually obtained from `crate::responses::Channel`,
423+
/// e.g. via `Client#list_channels`, `Client#list_channels_in`, `Client#list_channels_on`.
424+
/// See [Channels Guide](https://www.rabbitmq.com/docs/channels) to learn more.
425+
pub async fn get_channel_info<S: AsRef<str>>(&self, channel_name: S) -> Result<responses::Channel> {
426+
self.get_api_request(path!("channels", channel_name.as_ref()))
427+
.await
428+
}
429+
415430
/// Lists all stream publishers across the cluster.
416431
pub async fn list_stream_publishers(&self) -> Result<Vec<responses::StreamPublisher>> {
417432
let response = self

src/blocking_api.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ use crate::responses::{
2525
OAuthConfiguration, VirtualHostDefinitionSet, WarmStandbyReplicationStatus,
2626
};
2727
use crate::{
28-
commons::{BindingDestinationType, SupportedProtocol, UserLimitTarget, VirtualHostLimitTarget},
28+
commons::{
29+
BindingDestinationType, SupportedProtocol, UserLimitTarget,
30+
VirtualHostLimitTarget,
31+
},
2932
path,
3033
requests::{
3134
self, BulkUserDelete, EnforcedLimitParams, ExchangeParams, Permissions, PolicyParams,
@@ -392,6 +395,17 @@ where
392395
self.get_api_request(path!("connections", connection_name, "channels"))
393396
}
394397

398+
/// Returns information about a specific channel.
399+
///
400+
/// Unlike AMQP 0-9-1, HTTP API identifies channels by a string identifier instead of a numeric ID.
401+
///
402+
/// Channel name is usually obtained from `crate::responses::Channel`,
403+
/// e.g. via `Client#list_channels`, `Client#list_channels_in`, `Client#list_channels_on`.
404+
/// See [Channels Guide](https://www.rabbitmq.com/docs/channels) to learn more.
405+
pub fn get_channel_info<S: AsRef<str>>(&self, channel_name: S) -> Result<responses::Channel> {
406+
self.get_api_request(path!("channels", channel_name.as_ref()))
407+
}
408+
395409
/// Lists all stream publishers across the cluster.
396410
pub fn list_stream_publishers(&self) -> Result<Vec<responses::StreamPublisher>> {
397411
self.get_api_request(path!("stream", "publishers"))

tests/async_channel_tests.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
use amqprs::connection::{Connection, OpenConnectionArguments};
14+
use amqprs::{channel::ConfirmSelectArguments, connection::{Connection, OpenConnectionArguments}};
1515
use rabbitmq_http_client::api::Client;
1616
use std::time::Duration;
1717

@@ -86,3 +86,36 @@ async fn test_async_list_channels_on_connection() {
8686
ch.close().await.unwrap();
8787
conn.clone().close().await.unwrap();
8888
}
89+
90+
#[tokio::test]
91+
async fn test_async_get_channel_info() {
92+
let endpoint = endpoint();
93+
let rc = Client::new(&endpoint, USERNAME, PASSWORD);
94+
95+
let args = OpenConnectionArguments::new(&hostname(), 5672, USERNAME, PASSWORD);
96+
let conn = Connection::open(&args).await.unwrap();
97+
assert!(conn.is_open());
98+
99+
let ch = conn.open_channel(None).await.unwrap();
100+
assert!(ch.is_open());
101+
let _ = ch.confirm_select(ConfirmSelectArguments::default()).await;
102+
103+
tokio::time::sleep(Duration::from_millis(1000)).await;
104+
105+
let channels = rc.list_channels().await.unwrap();
106+
assert!(!channels.is_empty(), "Expected at least one channel");
107+
108+
let first_channel = channels.first().unwrap();
109+
110+
// Note: the HTTP API uses a string channel name, not the numeric ID
111+
let result1 = rc.get_channel_info(&first_channel.name).await;
112+
assert!(result1.is_ok(), "get_channel_info returned {result1:?}");
113+
114+
let ch_details = result1.unwrap();
115+
assert_eq!(ch_details.vhost, "/");
116+
assert_eq!(ch_details.consumer_count, 0, "Expected 0 consumers");
117+
118+
// just to be explicit
119+
ch.close().await.unwrap();
120+
conn.clone().close().await.unwrap();
121+
}

0 commit comments

Comments
 (0)