++ed by:
PLU

1 PAUSE user

Ioana Budai
and 1 contributors

NAME

Net::RabbitMQ::Management::API - Interface to the HTTP Rest API of the RabbitMQ management plugin

VERSION

version 0.01

SYNOPSIS

    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

DESCRIPTION

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.

ATTRIBUTES

ua

By default a LWP::UserAgent object but it can be anything that implements the same interface.

username

By default is guest. This can set the user for the API calls.

password

By default is guest. This can set the password for the API calls.

url

Url for the API calls. Is mandatory.

METHODS

request

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:

This method always returns a Net::RabbitMQ::Management::API::Result object.

get_overview

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_nodes

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_node

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_extensions

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_configuration

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;

update_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_connections

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_connection

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' );

delete_connection

Close 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->delete_connection( name => 'foo' );

get_channels

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_channel

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_exchanges

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_exchanges_in_vhost

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_exchange

Get an individual exchange. This method accepts the following parameters:

  • name: mandatory string, name of the exchange

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->get_exchange( name => 'bar', vhost => '%2f' );

create_exchange

Create an individual exchange. This method accepts the following parameters:

  • name: mandatory string, name of the exchange

  • vhost: mandatory string, name of the vhost

  • 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_exchange

Delete an individual exchange. This method accepts the following parameters:

  • name: mandatory string, name of the exchange

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->delete_exchange( name => 'bar', vhost => '%2f' );

get_exchange_bindings_by_source

Get a list of all bindings in which a given exchange is the source. This method accepts the following parameters:

  • name: mandatory string, name of the exchange

  • vhost: mandatory string, name of the vhost

    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_exchange_bindings_by_destination

Get a list of all bindings in which a given exchange is the destination. This method accepts the following parameters:

  • name: mandatory string, name of the exchange

  • vhost: mandatory string, name of the vhost

    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_exchange_message

Publish a message to a given exchange. This method accepts the following parameters:

  • name: mandatory string, name of the exchange

  • vhost: mandatory string, name of the vhost

  • 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_queues

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_queues_in_vhost

Get a list of all queues 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_queues_in_vhost( vhost => '%2f' );

get_queue

Get an individual queue. This method accepts the following parameters:

  • name: mandatory string, name of the queue

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->get_queue( name => 'foo', vhost => '%2f' );

create_queue

Create an individual queue. This method accepts the following parameters:

  • name: mandatory string, name of the queue

  • vhost: mandatory string, name of the vhost

  • auto_delete: optional boolean

  • durable: optional boolean

  • 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_queue

Delete an individual queue. This method accepts the following parameters:

  • name: mandatory string, name of the queue

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->delete_queue( name => 'foo', vhost => '%2f' );

get_queue_bindings

Get a list of all bindings on a given queue. This method accepts the following parameters:

  • name: mandatory string, name of the queue

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->get_queue_bindings( name => 'foo', vhost => '%2f' );

delete_queue_contents

Delete contents of a queue. This method accepts the following parameters:

  • name: mandatory string, name of the queue

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->delete_queue_contents( name => 'foo', vhost => '%2f' );

get_queue_messages

Get messages from a queue. This method accepts the following parameters:

  • name: mandatory string, name of the queue

  • vhost: mandatory string, name of the vhost

  • 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_bindings

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_bindings_in_vhost

Get a list of all bindings 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_bindings_in_vhost( vhost => '%2f' );

get_bindings_between_exchange_and_queue

Get a list of all bindings between an exchange and a queue. This method accepts the following parameters:

  • vhost: mandatory string, name of the vhost

  • 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_bindings_between_exchange_and_queue

Create a new binding between an exchange and a queue. This method accepts the following parameters:

  • vhost: mandatory string, name of the vhost

  • exchange: mandatory string, name of the exchange

  • queue: mandatory string, name of the queue

  • 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_binding

Get an individual binding between an exchange and a queue. This method accepts the following parameters:

  • vhost: mandatory string, name of the vhost

  • exchange: mandatory string, name of the exchange

  • queue: mandatory string, name of the queue

  • 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_binding

Create an individual binding between an exchange and a queue. This method accepts the following parameters:

  • vhost: mandatory string, name of the vhost

  • exchange: mandatory string, name of the exchange

  • queue: mandatory string, name of the queue

  • name: mandatory string, name of the binding

    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_binding

Delete an individual binding between an exchange and a queue. This method accepts the following parameters:

  • vhost: mandatory string, name of the vhost

  • exchange: mandatory string, name of the exchange

  • queue: mandatory string, name of the queue

  • name: mandatory string, name of the binding

    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_vhosts

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_vhost

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_vhost

Create 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->create_vhost( name => 'foo' );

delete_vhost

Delete 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->delete_vhost( name => 'foo' );

get_vhost_permissions

Get a list of all permissions for a given 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_permissions( name => 'foo' );

get_users

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_user

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_user

Create an individual user. This method accepts the following parameters:

  • name: mandatory string, name of the user

  • 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_user

Delete 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->delete_user( name => 'name' );

get_user_permissions

Get a list of all permissions for a given 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_permissions( name => 'name' );

get_user_details

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_users_permissions

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_user_vhost_permissions

Get an individual permission of a user and virtual host. This method accepts the following parameters:

  • name: mandatory string, name of the user

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->get_user_vhost_permissions( name => 'name', vhost => '%2f' );

create_user_vhost_permissions

Create an individual permission of a user and virtual host. This method accepts the following parameters:

  • name: mandatory string, name of the user

  • vhost: mandatory string, name of the vhost

  • 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_user_vhost_permissions

Delete an individual permission of a user and virtual host. This method accepts the following parameters:

  • name: mandatory string, name of the user

  • vhost: mandatory string, name of the vhost

    my $a      = Net::RabbitMQ::Management::API->new( url => 'http://localhost:55672/api' );
    my $result = $a->delete_user_vhost_permissions(
        vhost     => '%2f',
        name      => 'name',
    );

vhost_aliveness_test

Declares a test queue, then publishes and consumes a message. 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->vhost_aliveness_test( vhost => '%2f' );

DOCUMENTATION

The documentation has been taken directly from RabbitMQ. Please also read the documentation there, since it might be more complete.

AUTHOR

Ioana Budai <hurith@gmail.com>

COPYRIGHT AND LICENSE

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.