RabbitMQ Management HTTP API

概述

RabbitMQ的所有访问资源都是用application/json类型,并且需要HTTP基本认证。默认的用户名密码是guest/guest。由于虚拟主机名字能够唯一标识对象,所以许多URIS使用虚拟主机的名字作为请求路径的一部分。默认虚拟主机的名字为“/”,这将会被编码为“%2F”。上传的json对象,必须明确指定强制键,并且可能有可选的主键,其他的键将会被忽略。缺少必须的键会导致错误。由于绑定在AMQP中没有名字或者IDs,我们根据它的属性合成一个。由于一般情况下很难预测此名称,所以你可以使用post到一个工厂uri来创建一个绑定。许多uris返回的是列表结构,这些uris可以包含sort和sort_reverse 的参数。 sort允许根据选择的字段进行排序,而sort_reverse将会反转sort的排序结果。sort参数可以包含子集,他们中间使用逗号分开,这将允许使用内嵌组件来排序列表;它不允许根据多个字段来排序。你可以使用columns参数限制每个返回的信息。这是由点分割的子字段的逗号分隔。

例子

get a list of vhosts:

curl -i u guest:guest http://localhost:15672/api/vhosts

HTTP/1.1 200 OK
cache-control: no-cache
content-length: 621
content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'
content-type: application/json
date: Sat, 18 Sep 2021 06:41:32 GMT
server: Cowboy
vary: accept, accept-encoding, origin

[{"cluster_state":{"rabbit@ME":"running"},"description":"Default virtual host","messages":1,"messages_details":{"rate":0.0},"messages_ready":1,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":0,"messages_unacknowledged_details":{"rate":0.0},"metadata":{"description":"Default virtual host","tags":[]},"name":"/","recv_oct":10612,"recv_oct_details":{"rate":0.0},"send_oct":9858,"send_oct_details":{"rate":0.0},"tags":[],"tracing":false},{"cluster_state":{"rabbit@ME":"running"},"description":"","metadata":{"description":"","tags":[]},"name":"cxx_vhost","tags":[],"tracing":false}]

get a list of channels, fast publisher first, restricting the info items we get back:

curl -i -u guest:guest 'http://localhost:15672/api/channels?sort=message_stats.publish_details.rate&sort_reverse=true&columns=name,message_stats.publsh_details.rate,message_stats.deliver_get_details.rate'

HTTP/1.1 200 OK
cache-control: no-cache
content-length: 186
content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'
content-type: application/json
date: Sat, 18 Sep 2021 07:21:20 GMT
server: Cowboy
vary: accept, accept-encoding, origin

[{"message_stats":[],"name":"127.0.0.1:54043 -> 127.0.0.1:5672 (1)"},{"message_stats":[],"name":"127.0.0.1:54036 -> 127.0.0.1:5672 (1)"},{"name":"127.0.0.1:53970 -> 127.0.0.1:5672 (1)"}]

create a new vhost:

curl -i -u guest:guest -H "content-type:application/json" -XPUT http://localhost:15672/api/vhosts/testVhost

HTTP/1.1 201 Created
content-length: 0
content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'
date: Sat, 18 Sep 2021 07:24:20 GMT
server: Cowboy
vary: accept, accept-encoding, origin

create a new exchange in the default virtual host:

curl -i -u guest:guest -H "content-type:application/json" -XPUT -d '{"type":"direct","durable":true}' http://localhost:15672/api/exchanges/%2F/test_exchange

HTTP/1.1 201 Created
content-length: 0
content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'
date: Sat, 18 Sep 2021 07:33:47 GMT
server: Cowboy

delete an exchange

curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/exchanges/%2F/test_exchange

HTTP/1.1 204 No Content
content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'
date: Sat, 18 Sep 2021 07:35:35 GMT
server: Cowboy
vary: accept, accept-encoding, origin

参考

GETPUTDELETEPOSTPathDescription
X/api/overviewVarious random bits of information that describe the whole system.
XX/api/cluster-nameName identifying this RabbitMQ cluster.
X/api/nodesA list of nodes in the RabbitMQ cluster.
X/api/nodes/nameAn individual node in the RabbitMQ cluster. Add "?memory=true" to get memory statistics, and "?binary=true" to get a breakdown of binary memory use (may be expensive if there are many small binaries in the system).
X/api/extensionsA list of extensions to the management plugin.
XX/api/definitions
/api/all-configuration (deprecated)
The server definitions - exchanges, queues, bindings, users, virtual hosts, permissions, topic permissions, and parameters. Everything apart from messages. POST to upload an existing set of definitions. Note that:
  • The definitions are merged. Anything already existing on the server but not in the uploaded definitions is untouched.
  • Conflicting definitions on immutable objects (exchanges, queues and bindings) will be ignored. The existing definition will be preserved.
  • Conflicting definitions on mutable objects will cause the object in the server to be overwritten with the object from the definitions.
  • In the event of an error you will be left with a part-applied set of definitions.
For convenience you may upload a file from a browser to this URI (i.e. you can use multipart/form-data as well as application/json) in which case the definitions should be uploaded as a form field named "file".
XX/api/definitions/vhostThe server definitions for a given virtual host - exchanges, queues, bindings and policies. POST to upload an existing set of definitions. Note that:
  • The definitions are merged. Anything already existing on the server but not in the uploaded definitions is untouched.
  • Conflicting definitions on immutable objects (exchanges, queues and bindings) will be ignored. The existing definition will be preserved.
  • Conflicting definitions on mutable objects will cause the object in the server to be overwritten with the object from the definitions.
  • In the event of an error you will be left with a part-applied set of definitions.
For convenience you may upload a file from a browser to this URI (i.e. you can use multipart/form-data as well as application/json) in which case the definitions should be uploaded as a form field named "file".
X/api/connectionsA list of all open connections. Use pagination parameters to filter connections.
X/api/vhosts/vhost/connectionsA list of all open connections in a specific virtual host. Use pagination parameters to filter connections.
XX/api/connections/nameAn individual connection. DELETEing it will close the connection. Optionally set the "X-Reason" header when DELETEing to provide a reason.
X/api/connections/name/channelsList of all channels for a given connection.
X/api/channelsA list of all open channels. Use pagination parameters to filter channels.
X/api/vhosts/vhost/channelsA list of all open channels in a specific virtual host. Use pagination parameters to filter channels.
X/api/channels/channelDetails about an individual channel.
X/api/consumersA list of all consumers.
X/api/consumers/vhostA list of all consumers in a given virtual host.
X/api/exchangesA list of all exchanges. Use pagination parameters to filter exchanges.
X/api/exchanges/vhostA list of all exchanges in a given virtual host. Use pagination parameters to filter exchanges.
XXX/api/exchanges/vhost/nameAn individual exchange. To PUT an exchange, you will need a body looking something like this:
{"type":"direct","auto_delete":false,"durable":true,"internal":false,"arguments":{}}
The type key is mandatory; other keys are optional.

When DELETEing an exchange you can add the query string parameter if-unused=true. This prevents the delete from succeeding if the exchange is bound to a queue or as a source to another exchange.

X/api/exchanges/vhost/name/bindings/sourceA list of all bindings in which a given exchange is the source.
X/api/exchanges/vhost/name/bindings/destinationA list of all bindings in which a given exchange is the destination.
X/api/exchanges/vhost/name/publishPublish a message to a given exchange. You will need a body looking something like:
{"properties":{},"routing_key":"my key","payload":"my body","payload_encoding":"string"}
All keys are mandatory. The payload_encoding key should be either "string" (in which case the payload will be taken to be the UTF-8 encoding of the payload field) or "base64" (in which case the payload field is taken to be base64 encoded).
If the message is published successfully, the response will look like:
{"routed": true}
routed will be true if the message was sent to at least one queue.

Please note that the HTTP API is not ideal for high performance publishing; the need to create a new TCP connection for each message published can limit message throughput compared to AMQP or other protocols using long-lived connections.

X/api/queuesA list of all queues. Use pagination parameters to filter queues.
X/api/queues/vhostA list of all queues in a given virtual host. Use pagination parameters to filter queues.
XXX/api/queues/vhost/nameAn individual queue. To PUT a queue, you will need a body looking something like this:
{"auto_delete":false,"durable":true,"arguments":{},"node":"rabbit@smacmullen"}
All keys are optional.

When DELETEing a queue you can add the query string parameters if-empty=true and / or if-unused=true. These prevent the delete from succeeding if the queue contains messages, or has consumers, respectively.

X/api/queues/vhost/name/bindingsA list of all bindings on a given queue.
X/api/queues/vhost/name/contentsContents of a queue. DELETE to purge. Note you can't GET this.
X/api/queues/vhost/name/actionsActions that can be taken on a queue. POST a body like:
{"action":"sync"}
Currently the actions which are supported are sync and cancel_sync.
X/api/queues/vhost/name/getGet messages from a queue. (This is not an HTTP GET as it will alter the state of the queue.) You should post a body looking like:
{"count":5,"ackmode":"ack_requeue_true","encoding":"auto","truncate":50000}
  • count controls the maximum number of messages to get. You may get fewer messages than this if the queue cannot immediately provide them.
  • ackmode determines whether the messages will be removed from the queue. If ackmode is ack_requeue_true or reject_requeue_true they will be requeued - if ackmode is ack_requeue_false or reject_requeue_false they will be removed.
  • encoding must be either "auto" (in which case the payload will be returned as a string if it is valid UTF-8, and base64 encoded otherwise), or "base64" (in which case the payload will always be base64 encoded).
  • If truncate is present it will truncate the message payload if it is larger than the size given (in bytes).

truncate is optional; all other keys are mandatory.

Please note that the get path in the HTTP API is intended for diagnostics etc - it does not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.

X/api/bindingsA list of all bindings.
X/api/bindings/vhostA list of all bindings in a given virtual host.
XX/api/bindings/vhost/e/exchange/q/queue

A list of all bindings between an exchange and a queue. Remember, an exchange and a queue can be bound together many times!

To create a new binding, POST to this URI. Request body should be a JSON object optionally containing two fields, routing_key (a string) and arguments (a map of optional arguments):

{"routing_key":"my_routing_key", "arguments":{"x-arg": "value"}}
All keys are optional. The response will contain a Location header telling you the URI of your new binding.

XX/api/bindings/vhost/e/exchange/q/queue/propsAn individual binding between an exchange and a queue. The props part of the URI is a "name" for the binding composed of its routing key and a hash of its arguments. props is the field named "properties_key" from a bindings listing response.
XX/api/bindings/vhost/e/source/e/destination

A list of all bindings between two exchanges, similar to the list of all bindings between an exchange and a queue, above.

To create a new binding, POST to this URI. Request body should be a JSON object optionally containing two fields, routing_key (a string) and arguments (a map of optional arguments):

{"routing_key":"my_routing_key", "arguments":{"x-arg": "value"}}
All keys are optional. The response will contain a Location header telling you the URI of your new binding.

XX/api/bindings/vhost/e/source/e/destination/propsAn individual binding between two exchanges. Similar to the individual binding between an exchange and a queue, above.
X/api/vhostsA list of all vhosts.
XXX/api/vhosts/nameAn individual virtual host. As a virtual host usually only has a name, you do not need an HTTP body when PUTing one of these. To set metadata on creation, provide a body like the following:
{"description":"virtual host description", "tags":"accounts,production"}
tags is a comma-separated list of tags. These metadata fields are optional. To enable / disable tracing, provide a body looking like:
{"tracing":true}
X/api/vhosts/name/permissionsA list of all permissions for a given virtual host.
X/api/vhosts/name/topic-permissionsA list of all topic permissions for a given virtual host.
X/api/vhosts/name/start/nodeStarts virtual host name on node node.
X/api/users/A list of all users.
X/api/users/without-permissionsA list of users that do not have access to any virtual host.
X/api/users/bulk-deleteBulk deletes a list of users. Request body must contain the list:
{"users" : ["user1", "user2", "user3"]}
XXX/api/users/nameAn individual user. To PUT a user, you will need a body looking something like this:
{"password":"secret","tags":"administrator"}
or:
{"password_hash":"2lmoth8l4H0DViLaK9Fxi6l9ds8=", "tags":"administrator"}
The tags key is mandatory. Either password or password_hash can be set. If neither are set the user will not be able to log in with a password, but other mechanisms like client certificates may be used. Setting password_hash to "" will ensure the user cannot use a password to log in. tags is a comma-separated list of tags for the user. Currently recognised tags are administratormonitoring and managementpassword_hash must be generated using the algorithm described here. You may also specify the hash function being used by adding the hashing_algorithm key to the body. Currently recognised algorithms are rabbit_password_hashing_sha256rabbit_password_hashing_sha512, and rabbit_password_hashing_md5.
X/api/users/user/permissionsA list of all permissions for a given user.
X/api/users/user/topic-permissionsA list of all topic permissions for a given user.
X/api/user-limitsLists per-user limits for all users.
X/api/user-limits/userLists per-user limits for a specific user.
XX/api/user-limits/user/nameSet or delete per-user limit for user. The name URL path element refers to the name of the limit (max-connectionsmax-channels). Limits are set using a JSON document in the body:
{"value": 100}
. Example request:
curl -4u 'guest:guest' -H 'content-type:application/json' -X PUT localhost:15672/api/user-limits/guest/max-connections -d '{"value": 50}'
X/api/whoamiDetails of the currently authenticated user.
X/api/permissionsA list of all permissions for all users.
XXX/api/permissions/vhost/userAn individual permission of a user and virtual host. To PUT a permission, you will need a body looking something like this:
{"configure":".*","write":".*","read":".*"}
All keys are mandatory.
X/api/topic-permissionsA list of all topic permissions for all users.
XXX/api/topic-permissions/vhost/userTopic permissions for a user and virtual host. To PUT a topic permission, you will need a body looking something like this:
{"exchange":"amq.topic","write":"^a","read":".*"}
All keys are mandatory.
X/api/parametersA list of all vhost-scoped parameters.
X/api/parameters/componentA list of all vhost-scoped parameters for a given component.
X/api/parameters/component/vhostA list of all vhost-scoped parameters for a given component and virtual host.
XXX/api/parameters/component/vhost/nameAn individual vhost-scoped parameter. To PUT a parameter, you will need a body looking something like this:
{"vhost": "/","component":"federation","name":"local_username","value":"guest"}
X/api/global-parametersA list of all global parameters.
XXX/api/global-parameters/nameAn individual global parameter. To PUT a parameter, you will need a body looking something like this:
{"name":"user_vhost_mapping","value":{"guest":"/","rabbit":"warren"}}
X/api/policiesA list of all policies.
X/api/policies/vhostA list of all policies in a given virtual host.
XXX/api/policies/vhost/nameAn individual policy. To PUT a policy, you will need a body looking something like this:
{"pattern":"^amq.", "definition": {"federation-upstream-set":"all"}, "priority":0, "apply-to": "all"}
pattern and definition are mandatory, priority and apply-to are optional.
X/api/operator-policiesA list of all operator policy overrides.
X/api/operator-policies/vhostA list of all operator policy overrides in a given virtual host.
XXX/api/operator-policies/vhost/nameAn individual operator policy. To PUT a policy, you will need a body looking something like this:
{"pattern":"^amq.", "definition": {"expires":100}, "priority":0, "apply-to": "queues"}
pattern and definition are mandatory, priority and apply-to are optional.
X/api/aliveness-test/vhostDeclares a test queue on the target node, then publishes and consumes a message. Intended to be used as a very basic health check. Responds a 200 OK if the check succeeded, otherwise responds with a 503 Service Unavailable.
X/api/health/checks/alarmsResponds a 200 OK if there are no alarms in effect in the cluster, otherwise responds with a 503 Service Unavailable.
X/api/health/checks/local-alarmsResponds a 200 OK if there are no local alarms in effect on the target node, otherwise responds with a 503 Service Unavailable.
X/api/health/checks/certificate-expiration/within/unit

Checks the expiration date on the certificates for every listener configured to use TLS. Responds a 200 OK if all certificates are valid (have not expired), otherwise responds with a 503 Service Unavailable.

Valid units: days, weeks, months, years. The value of the within argument is the number of units. So, when within is 2 and unit is "months", the expiration period used by the check will be the next two months.

X/api/health/checks/port-listener/portResponds a 200 OK if there is an active listener on the give port, otherwise responds with a 503 Service Unavailable.
X/api/health/checks/protocol-listener/protocolResponds a 200 OK if there is an active listener for the given protocol, otherwise responds with a 503 Service Unavailable. Valid protocol names are: amqp091, amqp10, mqtt, stomp, web-mqtt, web-stomp.
X/api/health/checks/virtual-hostsResponds a 200 OK if all virtual hosts and running on the target node, otherwise responds with a 503 Service Unavailable.
X/api/health/checks/node-is-mirror-sync-criticalChecks if there are classic mirrored queues without synchronised mirrors online (queues that would potentially lose data if the target node is shut down). Responds a 200 OK if there are no such classic mirrored queues, otherwise responds with a 503 Service Unavailable.
X/api/health/checks/node-is-quorum-criticalChecks if there are quorum queues with minimum online quorum (queues that would lose their quorum and availability if the target node is shut down). Responds a 200 OK if there are no such quorum queues, otherwise responds with a 503 Service Unavailable.
X/api/vhost-limitsLists per-vhost limits for all vhosts.
X/api/vhost-limits/vhostLists per-vhost limits for specific vhost.
XX/api/vhost-limits/vhost/nameSet or delete per-vhost limit for vhost. The name URL path element refers to the name of the limit (max-connectionsmax-queues). Limits are set using a JSON document in the body:
{"value": 100}
. Example request:
curl -4u 'guest:guest' -H 'content-type:application/json' -X PUT localhost:15672/api/vhost-limits/my-vhost/max-connections -d '{"value": 50}'
X/api/authDetails about the OAuth2 configuration. It will return HTTP status 200 with body:
{"enable_uaa":"boolean", "uaa_client_id":"string", "uaa_location":"string"}
X/api/rebalance/queuesRebalances all queues in all vhosts. This operation is asynchronous therefore please check the RabbitMQ log file for messages regarding the success or failure of the operation.
curl -4u 'guest:guest' -XPOST localhost:15672/api/rebalance/queues/
X/api/federation-links
/api/federation-links/vhost
Provides status for all federation links. Requires the rabbitmq_federation_management plugin to be enabled.
XX/api/auth/attempts/nodeA list of authentication attempts.
XX/api/auth/attempts/node/sourceA list of authentication attempts by remote address and username.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值