-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Overview
RabbitHub is a RabbitMQ plugin-based implementation of PubSubHubBub (a simple web-hook-based pub/sub protocol) that provides an HTTP-based interface to RabbitMQ. It gives every AMQP exchange and queue hosted by the broker two URL’s: one to use for delivering messages to the exchange or queue, and one to use to subscribe to messages forwarded on by the exchange or queue. Subscriptions supply a callback URL to RabbitHub that is used to deliver messages via HTTP POST. While the initial aim of the plugin was support for PubSubHubBub, the plugin provides a generally useful, easy to use, and efficient means of interacting with RabbitMQ in a RESTful manner. When used in combination with other plugins such as those for STOMP, WebSockets, and MQTT, the result is an extremely powerful and flexible messaging solution. Messages may be published via one protocol and consumed by another (or indeed by multiple protocols when messages are published to fanout or topic exchanges).
RabbitHub was originally written by Tony Garnock-Jones (one of the original members of the RabbitMQ team) in 2009; however RabbitMQ has evolved considerably since this time, and it has been necessary to update the code in order for it to work with current RabbitMQ versions. The updated code and additional notes can be found at https://github.com/tonyg/rabbithub, and the binary distribution (which also happens to include the sources) can be found here.
Requirements for 3.6.6 version
- Erlang 18.3 or higher (also tested with 19.2) This is due to SSL bugs in 17.*
- RabbitMQ 3.6.6
The plugin is easily installed and configured according to the following steps:
- Copy the binary distribution (rabbithub.ez) to the RabbitMQ plugins directory. Assuming a standard Ubuntu distribution and RabbitMQ version 3.6.6, this may be done as follows:
- Enable the plugin:
- Restart RabbitMQ:
Note that by default the RabbitHub plugin will use TCP/IP port 55670. This may be changed by editing rabbitmq.config and restarting RabbitMQ (see http://www.rabbitmq.com/mochiweb.html for details). As currently implemented, the port used by the RabbitHub plugin (55670) clashes with that used by RabbitMQ-Web-Stomp, so be wary of enabling both plugins! We will see about fixing this shortly (there are probably one or two other related things that need to be tidied up also).
Usage
The plugin is extremely simple to use. The following basic operations are supported (illustrated using a few simple cURL commands):
- Create queue
$ curl -v -X PUT http://guest:guest@localhost:55670/endpoint/q/foo
- Delete queue
$ curl -v -X DELETE http://guest:guest@localhost:55670/endpoint/q/foo
- Create exchange
$ curl -X PUT http://guest:guest@localhost:55670/endpoint/x/junk
Note that the exchange type will by default be “fanout”. If you wish to create another type of exchange then you can do so by specifying the type in the query string. For example, appending the following query string to the above URL would cause a “direct” exchange to be created:
amqp.exchange_type=direct
- Delete exchange
$ curl -X DELETE http://guest:guest@localhost:55670/endpoint/x/junk
- Subscribe to an exchange
curl -vd \"hub.mode=subscribe&hub.callback=http://10.1.1.8:4567/sub1&hub.topic=foo&hub.verify=sync&hub.verify=async&hub.lease_seconds=86400" \http://guest:guest@localhost:55670/subscribe/x/amq.direct
For a detailed description of the various query string name-value pairs the reader should refer to the PubSubHubBub specification (see http://code.google.com/p/pubsubhubbub/); however the key points are hopefully summarised in the following table:
Parameter | Description |
hub.callback | The URL to which RabbitHub should post each message to as it arrives |
hub.topic | A filter for selecting a subset of messages |
hub.verify | The subscription verification mode for this request (the value may be either “sync” or “async”). Refer to the PubSubHubBub specification for additional details. |
hub.lease | Subscriber-provided lease duration in seconds. After this time, the subscription will be terminated. The default lease is approximately 30 days, and the maximum lease is approximately 1000 years. Refer to the PubSubHubBub specification for additional information. |
- Subscribe to a queue
curl -vd \"hub.mode=subscribe&hub.callback=http://10.1.1.8:4567/sub2&hub.topic=foo&hub.verify=sync&hub.lease_seconds=86400" \http://guest:guest@localhost:55670/subscribe/q/foo
As with subscribing to an exchange, upon receipt of the subscription request, RabbitHub will send a token to the specified callback URL, and the callback URL must respond with the same token in the body of the response. If the callback URL fails to respond correctly, the subscription will not be accepted.
- Unsubscribe
curl -vd "hub.mode=unsubscribe&hub.callback=http://10.1.1.8:4567/sub2&hub.topic=foo&hub.verify=sync&<token>" http://guest:guest@localhost:55670/subscribe/x/amq.direct
- Send a message to an exchange
curl -v -d "test message" \ http://guest:guest@localhost:55670/endpoint/x/amq.direct?hub.topic=foo
When fanout or topic exchanges are used, all subscribers will be POSTed a copy of the message using their nominated callback URL’s.
- Send a message to a queue
$ curl -d "another test message" \http://guest:guest@localhost:55670/endpoint/q/foo?hub.topic=rk
General format of RabbitHub URL’s
You will notice that URL’s are basically of two types:
- Endpoint URL’s for delivering messages (and issuing HTTP PUT and DELETE commands)
- Subscription URL’s