大忙人系列_RabbitMQ通过java HttpClient代码获取服务器上的所有交换机、队列

本文介绍了如何通过Java的HttpClient库访问RabbitMQ的HTTP API来获取服务器上的交换机和队列信息。在尝试过程中遇到了405和401错误,最终发现需要使用HTTP Basic认证才能成功。调整代码后,实现了正确获取RabbitMQ数据的目标。
摘要由CSDN通过智能技术生成

如图所示,我们可以找到HttpClient的API地址,通过账号密码我们可以在浏览器中获得相关的RabbitMQ的数据。

当我们获得所有的API以后,我们可以通过HttpClient远程调用API获得RabbitMQ的队列、交换机等信息。

但是我们是使用HttpClient会获得如下异常:

错误一:报405异常

18:18:05.793 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
18:18:05.819 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
18:18:05.821 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:15672][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
18:18:05.855 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://127.0.0.1:15672][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
18:18:05.858 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://127.0.0.1:15672
18:18:05.864 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to /127.0.0.1:15672
18:18:05.867 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:15649<->127.0.0.1:15672
18:18:05.867 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request POST /api/exchanges HTTP/1.1
18:18:05.868 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
18:18:05.869 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
18:18:05.874 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /api/exchanges HTTP/1.1
18:18:05.874 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 0
18:18:05.874 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: 127.0.0.1:15672
18:18:05.874 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
18:18:05.874 
  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值