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 supports 3 most recent Go releases.
Supported RabbitMQ Versions
All versions require RabbitMQ Management UI plugin to be installed and enabled.
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 (80-90%) 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
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"
)
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
res, 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 := SaltedPasswordHashSHA256("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")
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 Shovels
qs, err := rmqc.ListShovels()
qs, err := rmqc.ListShovelsIn("/")
q, err := rmqc.GetShovel("/", "a.shovel")
shovelDetails := rabbithole.ShovelDefinition{SourceURI: "amqp://sourceURI", SourceQueue: "mySourceQueue", DestinationURI: "amqp://destinationURI", DestinationQueue: "myDestQueue", AddForwardHeaders: true, AckMode: "on-confirm", DeleteAfter: "never"}
resp, err := rmqc.DeclareShovel("/", "a.shovel", shovelDetails)
resp, err := rmqc.DeleteShovel("/", "a.shovel")
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.Transport
...
rmqc.SetTransport(transport)
CI Status
Contributing
See CONTRIBUTING.md
License & Copyright
2-clause BSD license.
(c) Michael S. Klishin, 2013-2019.