-
-
30 Jun 2019 15:23:18 UTC
- Distribution: MsgPack-RPC
- Module version: v2.0.3
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (248 / 1 / 36)
- Kwalitee
Bus factor: 1- 82.04% Coverage
- License: perl_5
- Perl: v5.20.0
- Activity
24 month- Tools
- Download (33.59KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Beam::Emitter
- Beam::Event
- Carp
- Exporter::Tiny
- IO::Async::Loop
- IO::Async::Stream
- IO::Async::Timer::Countdown
- List::AllUtils
- List::Util
- Log::Any
- Module::Runtime
- Moose
- MooseX::MungeHas
- MooseX::NonMoose
- Promises
- Scalar::Util
- Type::Tiny
- Types::Standard
- experimental
- overload
- strict
- warnings
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
MsgPack::RPC - MessagePack RPC client
VERSION
version 2.0.3
SYNOPSIS
use MsgPack::RPC; my $rpc = MsgPack::RPC->new( io => '127.0.0.1:6666' ); $rpc->notify( 'something' => [ 'with', 'args' ] ); $rpc->request( request_method => [ 'some', 'args' ] )->on_done(sub{ print "replied with: ", @_; }); $rpc->loop;
DESCRIPTION
MsgPack::RPC
implements a MessagePack RPC client following the protocol described at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md.METHODS
new( %args )
- io( $socket )
- io( [ $in_fh, $out_fh ] )
-
Required. Defines which IO on which the MessagePack messages will be received and sent.
The IO can be a local socket (e.g.,
/tmp/rpc.socket
), a network socket (e.g.,127.0.0.1:6543
), or a pair of filehandles.
io()
Returns the IO descriptor(s) used by the object.
request( $method, $args, $id )
Sends the request. The
$id
is optional, and will be automatically assigned from an internal self-incrementing list if not given.Returns a promise that will be fulfilled once a response is received. The response can be either a success or a failure, and in both case the fulfilled promise will be given whatever values are passed in the response.
$rpc->request( 'ls', [ '/home', '/tmp' ] ) ->on_done(sub{ say for @_ }) ->on_fail(sub{ die "couldn't read directories: ", @_ });
notify( $method, $args )
Sends a notification.
subscribe( $event_name, \&callback )
# 'ping' is a request $rpc->subscribe( ping => sub($msg) { $msg->response->done('pong'); }); # 'log' is a notification $rpc->subscribe( log => sub($msg) { print {$fh} @{$msg->args}; });
Register a callback for the given event. If a notification or a request matching the event is received, the callback will be called. The callback will be passed either a MsgPack::RPC::Message (if triggered by a notification) or MsgPack::RPC::Message::Request object.
Events can have any number of callbacks assigned to them.
The subscription system is implemented using the Beam::Emitter role.
loop( $end_condition )
Reads and process messages from the incoming stream, endlessly if not be given an optional
$end_condition
. The end condition can be given a number of messages to read, or a promise that will end the loop once fulfilled.# loop until we get a response from our request my $response = $rpc->request('add', [1,2] ); $response->on_done(sub{ print "sum is ", @_ }); $rpc->loop($response); # loop 100 times $rpc->loop(100);
SEE ALSO
- MsgPack::RPC::Message
- MsgPack::RPC::Message::Request
- MsgPack::Encoder
- MsgPack::Decoder
- Data::MessagePack (alternative to
MsgPack::Encoder
andMsgPack::Decoder
.
AUTHOR
Yanick Champoux <yanick@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019, 2017, 2016, 2015 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install MsgPack::RPC, copy and paste the appropriate command in to your terminal.
cpanm MsgPack::RPC
perl -MCPAN -e shell install MsgPack::RPC
For more information on module installation, please visit the detailed CPAN module installation guide.