WebService::Zaqar -- Wrapper around the Zaqar (aka Marconi) message queue API
use WebService::Zaqar; my $client = WebService::Zaqar->new( # base_url => 'https://dfw.queues.api.rackspacecloud.com/', base_url => 'http://localhost:8888', spore_description_file => 'share/marconi.spore.json'); # for Rackspace only my $token = $client->rackspace_authenticate('https://identity.api.rackspacecloud.com/v2.0/tokens', $rackspace_account, $rackspace_key); $client->create_queue(queue_name => 'pets'); $client->post_messages(queue_name => 'pets', payload => [ { ttl => 120, body => [ 'pony', 'horse', 'warhorse' ] }, { ttl => 120, body => [ 'little dog', 'dog', 'large dog' ] } ]); $client->post_messages(queue_name => 'pets', payload => [ { ttl => 120, body => [ 'aleax', 'archon', 'ki-rin' ] } ]);
This library is a Net::HTTP::Spore-based client for the message queue component of OpenStack, Zaqar (previously known as "Marconi").
On top of allowing you to make requests to a Zaqar endpoint, this library also supports Rackspace authentication using their Cloud Identity token system; see do_request.
do_request
(read-only string)
The base URL for all API queries, except for the Rackspace-specific authentication.
(read-only string, defaults to a new UUID)
All API queries should contain a "Client-ID" header (in practice, some appear to work without this header). If you do not provide a value, a new one will be built with Data::UUID.
The docs recommend reusing the same client UUID between restarts of the client.
(read-only optional string)
API key for Rackspace authentication endpoints.
URL for Rackspace authentication endpoints.
Your Rackspace API username.
(read-only object)
This is the Net::HTTP::Spore client build with the spore_description_file attribute. All API method calls will be delegated to this object.
spore_description_file
(read-only required file path or URL)
Path to the SPORE specification file or remote resource.
A spec file for Zaqar v1.0 is provided in the distribution (see share/marconi.spec.json).
(read-only string with default predicate)
The token is automatically set when calling rackspace_authenticate successfully. Once set, it will be sent in the "X-Auth-Token" header with each query.
rackspace_authenticate
Rackspace invalidates the token after 24h, at which point all the queries will start returning "401 Unauthorized". Consider using do_request to manage this for you.
(read-only boolean, defaults to false)
If this attribute is set to true, you are indicating that the endpoint needs authentication. This means that when a request wrapped with do_request fails with "401 Unauthorized", the client will try (re-)authenticating with rackspace_authenticate, using the values in rackspace_keystone_endpoint, rackspace_username and rackspace_api_key.
rackspace_keystone_endpoint
rackspace_username
rackspace_api_key
All methods listed in the API docs are implemented by the SPORE client. When a body is required, you must provide it via the payload parameter.
payload
See the share/marconi.spore.json file for the list of methods and their parameters.
All those methods can be called with an instance of WebService::Zaqar as invocant; they will be delegated to the SPORE client.
Unlike "regular" SPORE-based clients, you may use the special __url__ parameter to provide an already-built URL directly. This is helpful when trying to follow links provided by the API itself. E.g. when you make a claim on a queue, the server does not return the claim and message IDs; instead it returns URLs to the claim and messages, which you are then supposed to call if you want to release or update the claim, delete a message, etc.
__url__
my $response = $client->claim_messages(queue_name => 'potato'); my $claim_href = $response->header('Location'); $client->release_claim(__url__ => $claim_href);
my $response = $client->do_request(sub { $client->list_queues(limit => 20) }, { retries => 2 }, @etc);
This method can be used to manage token generation. The first argument should be a coderef; it will be executing within a try { } statement. If the coderef throws a blessed exception of class Net::HTTP::Spore::Response (or a subclass thereof), that response's status is "401 Unauthorized", and wants_auth was set to a true value, rackspace_authenticate will be called and the coderef will be retried.
try { }
wants_auth
If the exception has another status code, it will be rethrown as-is, without retrying. This generally leads to a somewhat cryptic "HTTP response: 403" exception, since Net::HTTP::Spore::Response objects stringify to their status code. If the status code was 599 (internal exception), the response's error message will be thrown instead.
If the exception is not a Net::HTTP::Spore::Response instance at all, it will be rethrown directly.
Otherwise, the coderef's return value is returned.
The second argument is a hashref of options. Currently only "retries" is implemented:
The coderef will be called with the original invocant of do_request and the rest of the arguments of do_request as parameters.
my $token = $client->rackspace_authenticate('https://identity.api.rackspacecloud.com/v2.0/tokens', $rackspace_account, $rackspace_key);
Sends an HTTP request to a Cloud Identity endpoint (or compatible) and sets the token received.
See also "token".
The following modifications are applied to requests before they are made, in order:
X-Auth-Token
Date
Client-ID
client_uuid
The following modifications are applied to responses before they are returned, in order:
Net::HTTP::Spore
Fabrice Gabolde <fgabolde@weborama.com>
Copyright (C) 2014 Weborama
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
To install WebService::Zaqar, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebService::Zaqar
CPAN shell
perl -MCPAN -e shell install WebService::Zaqar
For more information on module installation, please visit the detailed CPAN module installation guide.