• Stars
    star
    404
  • Rank 104,473 (Top 3 %)
  • Language
    Go
  • License
    BSD 2-Clause "Sim...
  • Created over 10 years ago
  • Updated 25 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RabbitMQ HTTP API client in Go

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

Travis CI Tests

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:

// URI, username, password
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()
// => []NodeInfo, err

node, err := rmqc.GetNode("rabbit@mercurio")
// => NodeInfo, err

Operations on Connections

xs, err := rmqc.ListConnections()
// => []ConnectionInfo, err

conn, err := rmqc.GetConnection("127.0.0.1:50545 -> 127.0.0.1:5672")
// => ConnectionInfo, err

// Forcefully close connection
_, err := rmqc.CloseConnection("127.0.0.1:50545 -> 127.0.0.1:5672")
// => *http.Response, err

Operations on Channels

xs, err := rmqc.ListChannels()
// => []ChannelInfo, err

ch, err := rmqc.GetChannel("127.0.0.1:50545 -> 127.0.0.1:5672 (1)")
// => ChannelInfo, err

Operations on Vhosts

xs, err := rmqc.ListVhosts()
// => []VhostInfo, err

// information about individual vhost
x, err := rmqc.GetVhost("/")
// => VhostInfo, err

// creates or updates individual vhost
resp, err := rmqc.PutVhost("/", VhostSettings{Tracing: false})
// => *http.Response, err

// deletes individual vhost
resp, err := rmqc.DeleteVhost("/")
// => *http.Response, err

Managing Users

xs, err := rmqc.ListUsers()
// => []UserInfo, err

// information about individual user
x, err := rmqc.GetUser("my.user")
// => UserInfo, err

// creates or updates individual user
resp, err := rmqc.PutUser("my.user", UserSettings{Password: "s3krE7", Tags: "management,policymaker"})
// => *http.Response, err

// creates or updates individual user with no password
resp, err := rmqc.PutUserWithoutPassword("my.user", UserSettings{Tags: "management,policymaker"})
// => *http.Response, err

// deletes individual user
resp, err := rmqc.DeleteUser("my.user")
// => *http.Response, err
// creates or updates individual user with a Base64-encoded SHA256 password hash
hash := Base64EncodedSaltedPasswordHashSHA256("password-s3krE7")
resp, err := rmqc.PutUser("my.user", UserSettings{
  PasswordHash: hash,
  HashingAlgorithm: HashingAlgorithmSHA256,
  Tags: "management,policymaker"})
// => *http.Response, err

Managing Permissions

xs, err := rmqc.ListPermissions()
// => []PermissionInfo, err

// permissions of individual user
x, err := rmqc.ListPermissionsOf("my.user")
// => []PermissionInfo, err

// permissions of individual user in vhost
x, err := rmqc.GetPermissionsIn("/", "my.user")
// => PermissionInfo, err

// updates permissions of user in vhost
resp, err := rmqc.UpdatePermissionsIn("/", "my.user", Permissions{Configure: ".*", Write: ".*", Read: ".*"})
// => *http.Response, err

// revokes permissions in vhost
resp, err := rmqc.ClearPermissionsIn("/", "my.user")
// => *http.Response, err

Operations on Exchanges

xs, err := rmqc.ListExchanges()
// => []ExchangeInfo, err

// list exchanges in a vhost
xs, err := rmqc.ListExchangesIn("/")
// => []ExchangeInfo, err

// information about individual exchange
x, err := rmqc.GetExchange("/", "amq.fanout")
// => ExchangeInfo, err

// declares an exchange
resp, err := rmqc.DeclareExchange("/", "an.exchange", ExchangeSettings{Type: "fanout", Durable: false})
// => *http.Response, err

// deletes individual exchange
resp, err := rmqc.DeleteExchange("/", "an.exchange")
// => *http.Response, err

Operations on Queues

qs, err := rmqc.ListQueues()
// => []QueueInfo, err

// list queues in a vhost
qs, err := rmqc.ListQueuesIn("/")
// => []QueueInfo, err

// information about individual queue
q, err := rmqc.GetQueue("/", "a.queue")
// => QueueInfo, err

// declares a queue
resp, err := rmqc.DeclareQueue("/", "a.queue", QueueSettings{Durable: false})
// => *http.Response, err

// deletes individual queue
resp, err := rmqc.DeleteQueue("/", "a.queue")
// => *http.Response, err

// purges all messages in queue
resp, err := rmqc.PurgeQueue("/", "a.queue")
// => *http.Response, err

// synchronises all messages in queue with the rest of mirrors in the cluster
resp, err := rmqc.SyncQueue("/", "a.queue")
// => *http.Response, err

// cancels queue synchronisation process
resp, err := rmqc.CancelSyncQueue("/", "a.queue")
// => *http.Response, err

Operations on Bindings

bs, err := rmqc.ListBindings()
// => []BindingInfo, err

// list bindings in a vhost
bs, err := rmqc.ListBindingsIn("/")
// => []BindingInfo, err

// list bindings of a queue
bs, err := rmqc.ListQueueBindings("/", "a.queue")
// => []BindingInfo, err

// list all bindings having the exchange as source
bs1, err := rmqc.ListExchangeBindingsWithSource("/", "an.exchange")
// => []BindingInfo, err

// list all bindings having the exchange as destinattion
bs2, err := rmqc.ListExchangeBindingsWithDestination("/", "an.exchange")
// => []BindingInfo, err

// declare a binding
resp, err := rmqc.DeclareBinding("/", BindingInfo{
	Source: "an.exchange",
	Destination: "a.queue",
	DestinationType: "queue",
	RoutingKey: "#",
})
// => *http.Response, err

// deletes individual binding
resp, err := rmqc.DeleteBinding("/", BindingInfo{
	Source: "an.exchange",
	Destination: "a.queue",
	DestinationType: "queue",
	RoutingKey: "#",
	PropertiesKey: "%23",
})
// => *http.Response, err

Operations on Feature Flags

xs, err := rmqc.ListFeatureFlags()
// => []FeatureFlag, err

// enable a feature flag
_, err := rmqc.EnableFeatureFlag("drop_unroutable_metric")
// => *http.Response, err

Operations on Shovels

qs, err := rmqc.ListShovels()
// => []ShovelInfo, err

// list shovels in a vhost
qs, err := rmqc.ListShovelsIn("/")
// => []ShovelInfo, err

// information about an individual shovel
q, err := rmqc.GetShovel("/", "a.shovel")
// => ShovelInfo, err

// declares 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)
// => *http.Response, err

// deletes an individual shovel
resp, err := rmqc.DeleteShovel("/", "a.shovel")
// => *http.Response, err

Operations on Runtime (vhost-scoped) Parameters

// list all runtime parameters
params, err := rmqc.ListRuntimeParameters()
// => []RuntimeParameter, error

// list all runtime parameters for a component
params, err := rmqc.ListRuntimeParametersFor("federation-upstream")
// => []RuntimeParameter, error

// list runtime parameters in a vhost
params, err := rmqc.ListRuntimeParametersIn("federation-upstream", "/")
// => []RuntimeParameter, error

// information about a runtime parameter
p, err := rmqc.GetRuntimeParameter("federation-upstream", "/", "name")
// => *RuntimeParameter, error

// declare or update a runtime parameter
resp, err := rmqc.PutRuntimeParameter("federation-upstream", "/", "name", FederationDefinition{
    Uri: URISet{"amqp://server-name"},
})
// => *http.Response, error

// remove a runtime parameter
resp, err := rmqc.DeleteRuntimeParameter("federation-upstream", "/", "name")
// => *http.Response, error

Operations on Federation Upstreams

// list all federation upstreams
ups, err := rmqc.ListFederationUpstreams()
// => []FederationUpstream, error

// list federation upstreams in a vhost
ups, err := rmqc.ListFederationUpstreamsIn("/")
// => []FederationUpstream, error

// information about a federated upstream
up, err := rmqc.GetFederationUpstream("/", "name")
// => *FederationUpstream, error

// declare or update a federation upstream
resp, err := rmqc.PutFederationUpstream("/", "name", FederationDefinition{
  Uri: URISet{"amqp://server-name"},
})
// => *http.Response, error

// delete an upstream
resp, err := rmqc.DeleteFederationUpstream("/", "name")
// => *http.Response, error

Managing Global Parameters

// list all global parameters
params, err := rmqc.ListGlobalParameters()
// => []GlobalRuntimeParameter, error

// get a global parameter
p, err := rmqc.GetGlobalParameter("name")
// => *GlobalRuntimeParameter, error

// declare or update a global parameter
resp, err := rmqc.PutGlobalParameter("name", map[string]interface{
    endpoints: "amqp://server-name",
})
// => *http.Response, error

// delete a global parameter
resp, err := rmqc.DeleteGlobalParameter("name")
// => *http.Response, error

Managing Policies

mypolicy := Policy{
	Vhost:      "/",
	Pattern:    "^.*$",
	ApplyTo:    "queues",
	Name:       "mypolicy",
	Priority:   0,
	Definition: PolicyDefinition{
		// map[string] interface{}
		"max-length-bytes": 1048576,
	},
}
resp, err := rmqc.PutPolicy("/", "mypolicy", mypolicy)
// => *http.Response, error
xs, err := rmqc.ListPolicies()
// => []Policy, error
x, err := rmqc.GetPolicy("/", "mypolicy")
// => *Policy, error
resp, err := rmqc.DeletePolicy("/", "mypolicy")
// => *http.Response, error

Operations on cluster name

// Get cluster name
cn, err := rmqc.GetClusterName()
// => ClusterName, err

// Rename cluster
resp, err := rmqc.SetClusterName(ClusterName{Name: "rabbitmq@rabbit-hole"})
// => *http.Response, err

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.

More Repositories

1

monger

Monger is an idiomatic Clojure MongoDB driver with sane defaults, batteries included, well documented, low overhead
Clojure
480
star
2

langohr

A small, feature complete Clojure client for RabbitMQ that embraces AMQP 0.9.1 model
Clojure
348
star
3

cucumber.el

Emacs mode for editing Cucumber plain text stories
Emacs Lisp
251
star
4

quartz-mongodb

A MongoDB-based store for the Quartz scheduler. This fork strives to be as feature complete as possible. Originally by MuleSoft.
Java
246
star
5

sous-chef

Develop & test your OpsCode Chef cookbooks with pleasure with Vagrant & VirtualBox
Ruby
237
star
6

quartzite

Quarzite is a thin idiomatic Clojure layer on top the Quartz Scheduler
Clojure
214
star
7

neocons

A feature rich idiomatic Clojure client for the Neo4J REST API
Clojure
201
star
8

pantomime

A tiny Clojure library that deals with MIME types (Internet media types)
JavaScript
194
star
9

validateur

Functional validations inspired by Ruby's ActiveModel
Clojure
183
star
10

cassandra-chef-cookbook

Chef cookbook for Apache Cassandra, DataStax Enterprise (DSE) and DataStax agent
Ruby
161
star
11

gdb-macros-for-ruby

GDB macros for Ruby processes inspection: by Jamis Buck, Mauricio Fernandez, Phillipe Hanrigou
119
star
12

urly

A tiny Clojure library that parses and attempts to unify URIs, URLs and relative values found in real world HTML anchors
Clojure
115
star
13

git-wtf

A Ruby script that displays detailed status of local & remote branches, whether they are merged, and so on
Ruby
109
star
14

welle

An expressive Clojure client for Riak with batteries included
Clojure
91
star
15

jdk_switcher

A yet another Ubuntu/Debian-specific tool that makes switching between multiple JDK versions a one liner
Shell
73
star
16

crawlista

Crawlista is a support library for Clojure applications that crawl the Web
HTML
66
star
17

neo4j-server-chef-cookbook

Chef cookbook for Neo4J Server (Community Edition)
HTML
52
star
18

merb-internals-handbook

A guide through internals of Merb, very fast, flexible and modular web framework in Ruby
45
star
19

propertied

Tiny Clojure library for working with Java property lists (java.util.Properties)
Clojure
36
star
20

chash

A yet another consistent hashing library for Clojure
Clojure
25
star
21

merb-messenger

Attempt to come up with a useable unified messaging interface for Merb
Ruby
20
star
22

english

New home for English gem code
Ruby
14
star
23

el4r

Emacs Lisp Ruby bridge: extend Emacs with Ruby (or Ruby apps with Emacs Lisp)
Ruby
14
star
24

vclock

A Clojure implementation of vector clocks, roughly ported from Riak Core
Clojure
13
star
25

rubyonrails23_unicorn_amqp_gem_example

An example Ruby on Rails 2.3 application that uses Ruby AMQP gem with Unicorn
Ruby
13
star
26

storygen

RSpec stories generator for Ruby on Rails applications
Ruby
12
star
27

riak_core_cowboy_example

An example app that uses Cowboy for HTTP and Riak Core for cluster membership and work distribution
Erlang
11
star
28

eventsource-netty5

EventSource (Server-Sent Events) Java client built with Netty 5. Based on the Netty 3.x implementation by Aslak Hellesรธy.
Java
11
star
29

gradle-chef-cookbook

A Gradle OpsCode Chef cookbook that provides an up-to-date Gradle version and uses a reasonable license (MIT)
Ruby
10
star
30

haskell-platform-chef-cookbook

OpsCode Chef cookbook that provisions GHC 7.4 (or 7.6) and Haskell Platform 2012.02
Ruby
10
star
31

acits

RabbitMQ clients interoperability test suite
Clojure
10
star
32

emacsd

Chronicles of my Emacs life, recorded in a git repository
Emacs Lisp
9
star
33

go-language-chef-cookbook

A Chef cookbook that provisions the Go programming language build toolchain (stable or tip versions)
Ruby
9
star
34

mqtt-tls-playground

Example scripts/sample programs that demonstrate MQTT-with-TLS connections with various clients
Java
8
star
35

cyclist

Tiny Clojure library that detects cyclic dependencies between named entities
Clojure
6
star
36

sbt-chef-cookbook

Chef cookbook for Scala SBT (Simple Build Tool) 0.10.1, currently supports Ubuntu and Debian
Ruby
5
star
37

kiev_ruby_barcamp_2009

Some examples from my talk on beauty of Ruby's object model and power of modules/mixins/traits
Ruby
5
star
38

clang-chef-cookbook

A Chef cookbook that provisions the Clang compiler
Ruby
5
star
39

nginx-x-accel-redirect-example-application

Nginx X-Accel-Redirect example running on Merb core.
Ruby
5
star
40

rubyshift2013_talks

Slides from my talks at RubyShift 2013
5
star
41

money.ex

Elixir library for working with monetary amounts and currencies
Elixir
4
star
42

adventures_with_ssl_talk

Adventures with SSL: Hitting One Wall at a Time
4
star
43

eurler.scala

Resharpening my Scala saw. Nothing to see here, really.
Scala
4
star
44

rmq-chat-load-testing-scripts

Ruby
4
star
45

apache-jackrabbit-chef-cookbook

Chef cookbook that provisions Apache Jackrabbit (standalone)
Ruby
4
star
46

leiningen-chef-cookbook

Chef cookbook that provisions Leiningen 2.x
Ruby
4
star
47

esl-erlang-chef-cookbook

An OpsCode Chef cookbook that provides recent Erlang releases via ErlangSolutions apt repository
Ruby
3
star
48

quartzite.listeners.amqp

Quartz listeners that publish events over AMQP. Developed to be used in Clojure projects with Quartzite.
Clojure
3
star
49

flexri

Like Ruby's ri but for ActionScript 3.0.
3
star
50

nginxctl

A little utility that makes working with custom (built from source) local Nginx instances a bit easier
Python
3
star
51

lapin

Experimental F# client for RabbitMQ. HIGHLY INCOMPLETE AND IMMATURE.
F#
3
star
52

elasticsearch-chef-cookbook

ElasticSearch Chef cookbook that uses official Debian packages
Ruby
3
star
53

travisci-sbt-packaging

SBT packging tailored for travis-ci.org needs. May include pre-release versions, highly opinionated changes or other customizations most SBT users will never care about
Shell
3
star
54

pypy-chef-cookbook

An OpsCode Chef cookbook for PyPy (stable releases)
Ruby
3
star
55

green_bunny

Groovy RabbitMQ client heavily inspired by Bunny, March Hare and Langohr
Groovy
3
star
56

amqp_broker_stress_tests

A collection of stress tests for AMQP (0.9.1) brokers
Ruby
3
star
57

momentum.experiments

Just a bunch of experiments, move along
Clojure
3
star
58

openstack-summit-tokyo-2015

Slides of my talk at OpenStack Summit Tokyo
3
star
59

standalone-lein

A distribution of Leinigen that can be embedded into packages and other tools
Shell
2
star
60

noir-1.3-example

Just an example of a Noir project with a bunch of database clients, templating libraries and Leiningen plugins
Clojure
2
star
61

dattrack

Small command line tool for Digitally Imported (http://di.fm) fans
Go
2
star
62

dattrack.js

dattrack ported to JavaScript to learn a little bit about NPM module development workflow
JavaScript
2
star
63

rabbitmq-java-client-gae-example

Demonstrates how to use RabbitMQ Java client 3.3's thread factory on Google App Engine
Java
2
star
64

naturally_sorted_pathname

Pathname with natural order sorting
Ruby
2
star
65

rabbitmq_java_client_issue_19

User-provided test that aims to reproduce rabbitmq/rabbitmq-java-client#19
Clojure
2
star
66

clj1062

A small project that reproduces CLJ-1062
Clojure
2
star
67

multilingual

Multilingual dictionary for the 21st century, implemented as a Safari 5 extension.
JavaScript
2
star
68

euler.erl

Just learning myself some Erlang. Nothing to see here, move along.
Erlang
1
star
69

phantomjs-chef-cookbook

Chef cookbook that provisions PhantomJS
Ruby
1
star
70

priority-consumer-examples

Examples that demonstrate various priority queueing scenarios with RabbitMQ, in Java
Java
1
star
71

sync-up

A tiny utility that updates groups of Git and Mercurial repositories
JavaScript
1
star
72

marc_language_codes

MARC language codes table for Ruby
Ruby
1
star
73

mrmm

CLI-based multi-repository milestone manager
Rust
1
star
74

ruby_barcamp_kiev_nov_2009

Slides & examples from my talks on SSL/TLS/HTTPS and advanced RSpec topics
Ruby
1
star
75

proxima

Nothing to see here yet, move along
Erlang
1
star
76

ldnclj-september-2013

Code from team 2 at London Clojure Dojo, September 2013
Clojure
1
star
77

tlspejo

A tiny TLS echo server developed as a code kata exercise and as a possible hackable version of OpenSSL's s_server
Go
1
star