lib/Myriad/Role/RPC.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/Myriad/RPC/Implementation/Redis.pm ↑ Summary lib/Test/Myriad.pm »
1 package Myriad::Role::RPC;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = '1.001'; # VERSION
7 our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY
8  
9 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =encoding utf8
12  
13 =head1 NAME
14  
15 Myriad::Role::RPC - microservice RPC abstraction
16  
17 =head1 SYNOPSIS
18  
19 my $rpc = $myriad->rpc;
20  
21 =head1 DESCRIPTION
22  
23 =head1 Implementation
24  
25 Note that this is defined as a rôle, so it does not provide
26 a concrete implementation - instead, see classes such as:
27  
28 =over 4
29  
30 =item * L<Myriad::RPC::Implementation::Redis>
31  
32 =item * L<Myriad::RPC::Implementation::Memory>
33  
34 =back
35  
36 =cut
37  
38 1 ▶no indirect qw(fatal);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 0 ▶use Myriad::RPC::Message;
Subroutine BEGIN: called CC=1 SCAR=2.6
44  
45 =head1 METHODS
46  
47 The following methods are required in any concrete classes which implement this rôle.
48  
49 =head2 start
50  
51 Activate RPC - begin listening for messages.
52  
53 Expected to return a L<Future> which resolves once we think this instance is ready
54 and able to process requests.
55  
56 =cut
57  
58 requires 'start';
59  
60 =head2 create_from_sink
61  
62 Register a new RPC method and attach a L<Ryu::Sink> to be able to publish messages when they are received.
63  
64 =cut
65  
66 requires 'create_from_sink';
67  
68 =head2 stop
69  
70 Deäctivate RPC - stop listening for messages.
71  
72 This is the counterpart to L</start>.
73  
74 Expected to return a L<Future> which resolves once we are guaranteed not to pick up
75 any further new requests.
76  
77 =cut
78  
79 requires 'stop';
80  
81 =head2 reply_success
82  
83 Reply back to the sender of the message with success payload.
84 The method will take the raw response and take care of how we are going to encapsulate it.
85  
86 =over 4
87  
88 =item * message - The message we are processing.
89  
90 =item * response - The success response.
91  
92 =back
93  
94 =cut
95  
96 requires 'reply_success';
97  
98 =head2 reply_error
99  
100 Same concept of C<reply_success> but for errors.
101  
102 =over 4
103  
104 =item * C<message> - the message we are processing
105  
106 =item * C<error> - the L<Myriad::Exception> that happened while processing the message
107  
108 =back
109  
110 =cut
111  
112 requires 'reply_error';
113  
114 =head2 drop
115  
116 This should be used to handle dead messages (messages that we couldn't even parse).
117  
118 It doesn't matter how the implementation is going to deal with it (delete it/ move it to another queue ..etc) the RPC handler
119 should call this method when it's unable to parse a message and we can't reply to the client.
120  
121 =over 4
122  
123 =item * C<id> - message id
124  
125 =back
126  
127 =cut
128  
129 requires 'drop';
130  
131 1;
132  
133 __END__
« lib/Myriad/RPC/Implementation/Redis.pm ↑ Summary lib/Test/Myriad.pm »