Rabbit Hole, a RabbitMQ HTTP API Client for Go
This library is a RabbitMQ HTTP API client for the Go language.
Supported Go Versions
Rabbit Hole targets two latests stable Go versions available at the time of the library release.
Older versions may work but this is not guaranteed.
Supported RabbitMQ Versions
All versions require RabbitMQ Management UI plugin to be installed and enabled.
Build Status

Project Maturity
Rabbit Hole is a mature library (first released in late 2013)
designed after a couple of other RabbitMQ HTTP API clients with stable
APIs. Breaking API changes are not out of the question but not without
a reasonable version bump.
It is largely feature complete and decently documented.
Change Log
If upgrading from an earlier release, please consult with
the change log.
Installation
go get github.com/michaelklishin/rabbit-hole/v2
# or, for v1.x:
# go get github.com/michaelklishin/rabbit-hole
Documentation
API Reference
API reference is available on godoc.org.
Continue reading for a list of example snippets.
Overview
To import the package:
import (
"github.com/michaelklishin/rabbit-hole/v2"
)
All HTTP API operations are accessible via rabbithole.Client
, which
should be instantiated with rabbithole.NewClient
:
rmqc, _ = NewClient("http://127.0.0.1:15672", "guest", "guest")
TLS (HTTPS) can be enabled by adding an HTTP transport to the parameters
of rabbithole.NewTLSClient
:
transport := &http.Transport{TLSClientConfig: tlsConfig}
rmqc, _ := NewTLSClient("https://127.0.0.1:15672", "guest", "guest", transport)
RabbitMQ HTTP API has to be configured to use TLS.
Getting Overview
resp, err := rmqc.Overview()
Node and Cluster Status
xs, err := rmqc.ListNodes()
node, err := rmqc.GetNode("rabbit@mercurio")
Operations on Connections
xs, err := rmqc.ListConnections()
conn, err := rmqc.GetConnection("127.0.0.1:50545 -> 127.0.0.1:5672")
_, err := rmqc.CloseConnection("127.0.0.1:50545 -> 127.0.0.1:5672")
Operations on Channels
xs, err := rmqc.ListChannels()
ch, err := rmqc.GetChannel("127.0.0.1:50545 -> 127.0.0.1:5672 (1)")
Operations on Vhosts
xs, err := rmqc.ListVhosts()
x, err := rmqc.GetVhost("/")
resp, err := rmqc.PutVhost("/", VhostSettings{Tracing: false})
resp, err := rmqc.DeleteVhost("/")
Managing Users
xs, err := rmqc.ListUsers()
x, err := rmqc.GetUser("my.user")
resp, err := rmqc.PutUser("my.user", UserSettings{Password: "s3krE7", Tags: "management,policymaker"})
resp, err := rmqc.PutUserWithoutPassword("my.user", UserSettings{Tags: "management,policymaker"})
resp, err := rmqc.DeleteUser("my.user")
hash := Base64EncodedSaltedPasswordHashSHA256("password-s3krE7")
resp, err := rmqc.PutUser("my.user", UserSettings{
PasswordHash: hash,
HashingAlgorithm: HashingAlgorithmSHA256,
Tags: "management,policymaker"})
Managing Permissions
xs, err := rmqc.ListPermissions()
x, err := rmqc.ListPermissionsOf("my.user")
x, err := rmqc.GetPermissionsIn("/", "my.user")
resp, err := rmqc.UpdatePermissionsIn("/", "my.user", Permissions{Configure: ".*", Write: ".*", Read: ".*"})
resp, err := rmqc.ClearPermissionsIn("/", "my.user")
Operations on Exchanges
xs, err := rmqc.ListExchanges()
xs, err := rmqc.ListExchangesIn("/")
x, err := rmqc.GetExchange("/", "amq.fanout")
resp, err := rmqc.DeclareExchange("/", "an.exchange", ExchangeSettings{Type: "fanout", Durable: false})
resp, err := rmqc.DeleteExchange("/", "an.exchange")
Operations on Queues
qs, err := rmqc.ListQueues()
qs, err := rmqc.ListQueuesIn("/")
q, err := rmqc.GetQueue("/", "a.queue")
resp, err := rmqc.DeclareQueue("/", "a.queue", QueueSettings{Durable: false})
resp, err := rmqc.DeleteQueue("/", "a.queue")
resp, err := rmqc.PurgeQueue("/", "a.queue")
resp, err := rmqc.SyncQueue("/", "a.queue")
resp, err := rmqc.CancelSyncQueue("/", "a.queue")
Operations on Bindings
bs, err := rmqc.ListBindings()
bs, err := rmqc.ListBindingsIn("/")
bs, err := rmqc.ListQueueBindings("/", "a.queue")
bs1, err := rmqc.ListExchangeBindingsWithSource("/", "an.exchange")
bs2, err := rmqc.ListExchangeBindingsWithDestination("/", "an.exchange")
resp, err := rmqc.DeclareBinding("/", BindingInfo{
Source: "an.exchange",
Destination: "a.queue",
DestinationType: "queue",
RoutingKey: "#",
})
resp, err := rmqc.DeleteBinding("/", BindingInfo{
Source: "an.exchange",
Destination: "a.queue",
DestinationType: "queue",
RoutingKey: "#",
PropertiesKey: "%23",
})
Operations on Feature Flags
xs, err := rmqc.ListFeatureFlags()
_, err := rmqc.EnableFeatureFlag("drop_unroutable_metric")
Operations on Shovels
qs, err := rmqc.ListShovels()
qs, err := rmqc.ListShovelsIn("/")
q, err := rmqc.GetShovel("/", "a.shovel")
shovelDetails := rabbithole.ShovelDefinition{
SourceURI: URISet{"amqp://sourceURI"},
SourceProtocol: "amqp091",
SourceQueue: "mySourceQueue",
DestinationURI: "amqp://destinationURI",
DestinationProtocol: "amqp10",
DestinationAddress: "myDestQueue",
DestinationAddForwardHeaders: true,
AckMode: "on-confirm",
SrcDeleteAfter: "never",
}
resp, err := rmqc.DeclareShovel("/", "a.shovel", shovelDetails)
resp, err := rmqc.DeleteShovel("/", "a.shovel")
Operations on Runtime (vhost-scoped) Parameters
params, err := rmqc.ListRuntimeParameters()
params, err := rmqc.ListRuntimeParametersFor("federation-upstream")
params, err := rmqc.ListRuntimeParametersIn("federation-upstream", "/")
p, err := rmqc.GetRuntimeParameter("federation-upstream", "/", "name")
resp, err := rmqc.PutRuntimeParameter("federation-upstream", "/", "name", FederationDefinition{
Uri: URISet{"amqp://server-name"},
})
resp, err := rmqc.DeleteRuntimeParameter("federation-upstream", "/", "name")
Operations on Federation Upstreams
ups, err := rmqc.ListFederationUpstreams()
ups, err := rmqc.ListFederationUpstreamsIn("/")
up, err := rmqc.GetFederationUpstream("/", "name")
resp, err := rmqc.PutFederationUpstream("/", "name", FederationDefinition{
Uri: URISet{"amqp://server-name"},
})
resp, err := rmqc.DeleteFederationUpstream("/", "name")
Managing Global Parameters
params, err := rmqc.ListGlobalParameters()
p, err := rmqc.GetGlobalParameter("name")
resp, err := rmqc.PutGlobalParameter("name", map[string]interface{
endpoints: "amqp://server-name",
})
resp, err := rmqc.DeleteGlobalParameter("name")
Managing Policies
mypolicy := Policy{
Vhost: "/",
Pattern: "^.*$",
ApplyTo: "queues",
Name: "mypolicy",
Priority: 0,
Definition: PolicyDefinition{
"max-length-bytes": 1048576,
},
}
resp, err := rmqc.PutPolicy("/", "mypolicy", mypolicy)
xs, err := rmqc.ListPolicies()
x, err := rmqc.GetPolicy("/", "mypolicy")
resp, err := rmqc.DeletePolicy("/", "mypolicy")
Operations on cluster name
cn, err := rmqc.GetClusterName()
resp, err := rmqc.SetClusterName(ClusterName{Name: "rabbitmq@rabbit-hole"})
HTTPS Connections
var tlsConfig *tls.Config
...
transport := &http.Transport{TLSClientConfig: tlsConfig}
rmqc, err := NewTLSClient("https://127.0.0.1:15672", "guest", "guest", transport)
Changing Transport Layer
var transport http.RoundTripper
...
rmqc.SetTransport(transport)
Contributing
See CONTRIBUTING.md
License & Copyright
2-clause BSD license.
(c) Michael S. Klishin and contributors, 2013-2023.