Net::RabbitMQ::Management::API - Interface to the HTTP Rest API of the RabbitMQ management plugin
version 0.01
use Net::RabbitMQ::Management::API; use Data::Dumper; my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_overview; # $result->content is either an arrayref or an hashref # depending on the API call that has been made printf "%s\n", Dumper $result->content; # prints random bits of information that describe the whole system
Net::RabbitMQ::Management::API provides a set of modules to access RabbitMQ in an object oriented way.
Note: This library has been tested against the RabbitMQ Management Plugin version 2.6.1.
By default a LWP::UserAgent object but it can be anything that implements the same interface.
By default is guest. This can set the user for the API calls.
By default is guest. This can set the password for the API calls.
Url for the API calls. Is mandatory.
All Net::RabbitMQ::Management::API calls are using this method for making requests to RabbitMQ. This method can be used directly. It accepts a hash with following keys:
method: mandatory string, one of the following:
DELETE
GET
PATCH
POST
PUT
path: mandatory string of the relative path used for making the API call.
data: optional data reference, usually a reference to an array or hash. It must be possible to serialize this using JSON::Any. This will be the HTTP request body.
Usually you should not end up using this method at all. It's only available if Net::RabbitMQ::Management::API is missing anything from the RabbitMQ API. Here are some examples of how to use it:
Same as "get_overview" in Net::RabbitMQ::Management::API:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->request( method => 'GET', path => '/overview', );
Same as "get_configuration" in Net::RabbitMQ::Management::API:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->request( method => 'GET', path => '/all-configuration', );
This method always returns a Net::RabbitMQ::Management::API::Result object.
Get various random bits of information that describe the whole system. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_overview;
Get a list of nodes in the RabbitMQ cluster. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_nodes;
Get an individual node in the RabbitMQ cluster. This method accepts the following parameters:
name: mandatory string, name of the node
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_node( name => 'foo' );
Get a list of extensions to the management plugin. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_extensions;
Get the server configuration. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_configuration;
Upload an existing server configuration. This method accepts the following parameters:
users: mandatory arrayref of hashrefs, list of users
vhosts: mandatory arrayref of hashrefs, list of vhosts
permissions: mandatory arrayref of hashrefs, list of permissions
queues: mandatory arrayref of hashrefs, list of queues
exchanges: mandatory arrayref of hashrefs, list of exchanges
bindings: mandatory arrayref of hashrefs, list of bindings
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->update_configuration( vhosts => [ { 'name' => '/' } ], bindings => [ { destination_type => 'queue', source => 'bar19', routing_key => 'my_routing_key', destination => 'bar123', vhost => '/', arguments => {}, } ], permissions => [ { vhost => '/', read => '.*', configure => '.*', user => 'guest', write => '.*' } ], exchanges => [ { vhost => '/', name => 'bar19', type => 'direct', arguments => {}, auto_delete => 'false', durable => 'true', } ], users => [ { password_hash => 'Vgg+GKF7tFByrur0Z+Gaj3jjaLM=', name => 'guest', tags => 'administrator' } ], queues => [ { vhost => '/', name => 'aliveness-test', arguments => {}, auto_delete => 'false', durable => 'true', }, { vhost => '/', name => 'bar123', arguments => {}, auto_delete => 'false', durable => 'true', } ] );
Get a list of all open connections. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_connections;
Get an individual connection. This method accepts the following parameters:
name: mandatory string, name of the connection
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_connection( name => 'foo' );
Close an individual connection. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_connection( name => 'foo' );
Get a list of all open channels. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_channels;
Get details about an individual channel. This method accepts the following parameters:
name: mandatory string, name of the channel
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_channel( name => 'foo' );
Get a list of all exchanges. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_exchanges;
Get a list of all exchanges in a given virtual host. This method accepts the following parameters:
vhost: mandatory string, name of the vhost
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_exchanges_in_vhost( vhost => '%2f' );
Get an individual exchange. This method accepts the following parameters:
name: mandatory string, name of the exchange
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_exchange( name => 'bar', vhost => '%2f' );
Create an individual exchange. This method accepts the following parameters:
type: mandatory string, type of the exchange
auto_delete: optional boolean
durable: optional boolean
internal: optional boolean
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_exchange( vhost => '%2f', name => 'bar', type => 'direct', auto_delete => 'false', durable => 'true', internal => 'false', );
Delete an individual exchange. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_exchange( name => 'bar', vhost => '%2f' );
Get a list of all bindings in which a given exchange is the source. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_exchange_bindings_by_source( name => 'bar', vhost => '%2f' );
Get a list of all bindings in which a given exchange is the destination. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_exchange_bindings_by_destination( name => 'bar', vhost => '%2f' );
Publish a message to a given exchange. This method accepts the following parameters:
routing_key: mandatory string
payload: mandatory string
payload_encoding: mandatory string
properties: mandatory hashref
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->publish_exchange_message( vhost => '%2f', name => 'foo', routing_key => 'my_routing_key', payload => 'my_body', payload_encoding => 'string', properties => {}, );
Get a list of all queues. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_queues;
Get a list of all queues in a given virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_queues_in_vhost( vhost => '%2f' );
Get an individual queue. This method accepts the following parameters:
name: mandatory string, name of the queue
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_queue( name => 'foo', vhost => '%2f' );
Create an individual queue. This method accepts the following parameters:
node: optional string
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_queue( name => 'foo', vhost => '%2f', auto_delete => 'false', durable => 'true', node => 'bar', );
Delete an individual queue. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_queue( name => 'foo', vhost => '%2f' );
Get a list of all bindings on a given queue. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_queue_bindings( name => 'foo', vhost => '%2f' );
Delete contents of a queue. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_queue_contents( name => 'foo', vhost => '%2f' );
Get messages from a queue. This method accepts the following parameters:
encoding: mandatory string, payload encoding type
auto
base64
count: mandatory integer, controls the number of messages to get
requeue: mandatory boolean, determines whether the messages will be removed from the queue
truncate: optional integer, if present, will truncate the message payload if it is larger than the size given (in bytes)
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_queue_messages( name => 'foo', vhost => '%2f', count => 0, requeue => 'true', truncate => 50000, encoding => 'auto', );
Get a list of all bindings. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_bindings;
Get a list of all bindings in a given virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_bindings_in_vhost( vhost => '%2f' );
Get a list of all bindings between an exchange and a queue. This method accepts the following parameters:
exchange: mandatory string, name of the exchange
queue: mandatory string, name of the queue
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_bindings_between_exchange_and_queue( vhost => '%2f', exchange => 'foo', queue => 'bar' );
Create a new binding between an exchange and a queue. This method accepts the following parameters:
routing_key: optional string
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_bindings_between_exchange_and_queue( vhost => '%2f', exchange => 'foo', queue => 'bar', routing_key => 'my_routing_key', );
Get an individual binding between an exchange and a queue. This method accepts the following parameters:
name: mandatory string, name of the binding
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_binding( vhost => '%2f', exchange => 'bar', queue => 'foo', name => 'binding', );
Create an individual binding between an exchange and a queue. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_binding( vhost => '%2f', exchange => 'bar', queue => 'foo', name => 'binding', );
Delete an individual binding between an exchange and a queue. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_binding( vhost => '%2f', exchange => 'bar', queue => 'foo', name => 'binding', );
Get a list of all vhosts. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_vhosts;
Get an individual virtual host. This method accepts the following parameters:
name: mandatory string, name of the vhost
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_vhost( name => 'foo' );
Create an individual virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_vhost( name => 'foo' );
Delete an individual virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_vhost( name => 'foo' );
Get a list of all permissions for a given virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_vhost_permissions( name => 'foo' );
Get a list of all users. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_users;
Get an individual user. This method accepts the following parameters:
name: mandatory string, name of the user
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_user( name => 'name' );
Create an individual user. This method accepts the following parameters:
tags: mandatory string
password: mandatory strings
password_hash: mandatory string
Either password or password_hash must be set.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_user( name => 'name', password_hash => 'ISsWSv7CvZZts2lfN+TJPvUkSdo=', tags => 'administrator', );
Delete an individual user. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_user( name => 'name' );
Get a list of all permissions for a given user. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_user_permissions( name => 'name' );
Get details of the currently authenticated user. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_user_details;
Get a list of all permissions for all users. This method does not require any parameters.
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_users_permissions;
Get an individual permission of a user and virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->get_user_vhost_permissions( name => 'name', vhost => '%2f' );
Create an individual permission of a user and virtual host. This method accepts the following parameters:
write: mandatory string
read: mandatory string
configure: mandatory string
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->create_user_vhost_permissions( vhost => '%2f', name => 'name', configure => '.*', write => '.*', read => '.*', );
Delete an individual permission of a user and virtual host. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->delete_user_vhost_permissions( vhost => '%2f', name => 'name', );
Declares a test queue, then publishes and consumes a message. This method accepts the following parameters:
my $a = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' ); my $result = $a->vhost_aliveness_test( vhost => '%2f' );
The documentation has been taken directly from RabbitMQ. Please also read the documentation there, since it might be more complete.
Ioana Budai <hurith@gmail.com>
This software is copyright (c) 2011 by Ioana Budai.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Net::RabbitMQ::Management::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::RabbitMQ::Management::API
CPAN shell
perl -MCPAN -e shell install Net::RabbitMQ::Management::API
For more information on module installation, please visit the detailed CPAN module installation guide.