Osgood::Client - Client for the Osgood Passive, Persistent Event Queue
Provides a client for sending events to or retrieving events from an Osgood queue.
To send some events:
my $event = Osgood::Event->new( object => 'Moose', action => 'farted', date_occurred => DateTime->now ); my $list = Osgood::EventList->new(events => [ $event ]) my $client = Osgood::Client->new( url => 'http://localhost', list => $list ); my $retval = $client->send; if($list->size == $retval) { print "Success :)\n"; } else { print "Failure :(\n"; }
To query for events
use DateTime; use Osgood::Client; use URI; my $client = Osgood::Client->new( url => URI->new('http://localhost:3000'), ); $client->query({ object => 'Moose', action => 'farted' }); if($client->list->size == 1) { print "Success\n"; } else { print "Failure\n"; }
Creates a new Osgood::Client object.
Set/Get the EventList. For sending events, you should set this. For retrieving them, this will be populated by query returns.
Send events to the server.
Query the Osgood server for events. Takes a hashref in the following format:
{ id => X, object => 'obj', action => 'foo', date => '2007-12-11' }
At least one key is required.
A true or false value is returned to denote the success of failure of the query. If false, then the error will be set in the error accessor. On success the list may be retrived from the list accessor.
Implicitly sets $self->list(undef), to clear previous results.
The number of seconds to wait before timing out.
The url of the Osgood queue we should contact. Expects an instance of URI.
Returns the error message (if there was one) for this client. This should be called if query or send do not return what you expect.
query
send
Originally Osgood used a combination of XML::DOM and XML::XPath for serialization. After some testing it has switched to using JSON, as JSON::XS is considerably faster. In tests on my machine (dual quad-core xeon) it takes about 10 seconds to deserialize 10_000 simple events.
Please keep in mind that the sending of events will also have a cost, as insertion into the database takes time. See the accompanying PERFORMANCE section of Osgood::Server.
Cory 'G' Watson <gphat@cpan.org>
Mike Eldridge (diz)
perl(1), Osgood::Event, Osgood::EventList
Copyright 2008-2009 by Magazines.com, LLC
You can redistribute and/or modify this code under the same terms as Perl itself.
To install Osgood::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Osgood::Client
CPAN shell
perl -MCPAN -e shell install Osgood::Client
For more information on module installation, please visit the detailed CPAN module installation guide.