NAME
McBain::WithZeroMQ - Load a McBain API as a ZeroMQ service
SYNOPSIS
# write your API as you normally would, and create
# a simple start-up script:
#!/usr/bin/perl -w
use warnings;
use strict;
use MyAPI -withZeroMQ;
MyAPI->work('localhost', 5560);
DESCRIPTION
"McBain::WithZeroMQ" turns your McBain API into a ZeroMQ REP worker,
making it easy to consume your APIs with ZMQ REQ clients. The generated
worker code is based on the request-reply worker example
<
http://zguide.zeromq.org/pl:rrworker> in the ZeroMQ guide
<
http://zguide.zeromq.org/page:all>. Note that the ZeroMQ request-reply
pattern requires a broker. The guide also has examples for a broker
<
http://zguide.zeromq.org/pl:rrbroker> and a client
<
http://zguide.zeromq.org/pl:rrclient>, though two scripts based on
these examples are also provided with this module - more for example
than actual usage - see mcbain-zmq-broker and mcbain-zmq-client,
respectively.
The workers created by this module receive payloads in JSON format, and
convert them into the hash-refs your API's methods expect to receive.
The payload must have a "path" key, which holds the complete path of the
route/method to invoke (for example, "GET:/math/sum"). Results are sent
back to the clients in JSON as well. Note that if an API method does not
return a hash-ref, this runner module will automatically turn it into a
hash-ref to ensure that conversion into JSON will be possible. The
created hash-ref will have one key - holding the method's name, with
whatever was returned from the method as its value. For example, if
method "GET:/divide" in topic "/math" returns an integer (say 7), then
the client will get the JSON "{ "GET:/math/divide": 7 }". To avoid, make
sure your API's methods return hash-refs.
METHODS EXPORTED TO YOUR API
work( [ $host, $port ] )
Connects the ZeroMQ worker created by the module to the ZeroMQ broker
listening at the host and port provided. If none are provided,
"localhost" and 5560 are used, respectively.
The method never returns, so that the worker listens for jobs
continuously.
METHODS REQUIRED BY MCBAIN
This runner module implements the following methods required by
"McBain":
init( )
Creates the "work( $host, $port )" method for the root topic of the API.
generate_env( $job )
Receives the JSON payload and generates "McBain"'s standard env hash-ref
from it.
generate_res( $env, $res )
Converts the result from an API method in JSON. Read the discussion
under "DESCRIPTION" for more info.
handle_exception( $err )
Simply calls "$job->send_fail" to return a job failed status to the
client.
CONFIGURATION AND ENVIRONMENT
No configuration files are required.
DEPENDENCIES
"McBain::WithZeroMQ" depends on the following CPAN modules:
* Carp
* ZMQ::Constants
* ZMQ::LibZMQ3
* JSON
INCOMPATIBILITIES WITH OTHER MODULES
None reported.
BUGS AND LIMITATIONS
Please report any bugs or feature requests to
"
[email protected]", or through the web interface at
<
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=McBain-WithZeroMQ>.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc McBain::WithZeroMQ
You can also look for information at:
* RT: CPAN's request tracker
<
http://rt.cpan.org/NoAuth/Bugs.html?Dist=McBain-WithZeroMQ>
* AnnoCPAN: Annotated CPAN documentation
<
http://annocpan.org/dist/McBain-WithZeroMQ>
* CPAN Ratings
<
http://cpanratings.perl.org/d/McBain-WithZeroMQ>
* Search CPAN
<
http://search.cpan.org/dist/McBain-WithZeroMQ/>
AUTHOR
Ido Perlmuter <
[email protected]>
SEE ALSO
McBain
LICENSE AND COPYRIGHT
Copyright (c) 2014, Ido Perlmuter "
[email protected]".
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either version 5.8.1 or any later
version. See perlartistic and perlgpl.
The full text of the license can be found in the LICENSE file included
with this module.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.