| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | |||
| 4 | package Jifty::Plugin::RPC; | ||
| 5 | use base qw/Jifty::Plugin/; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Jifty::Plugin::RPC - Use AMQP for RPC | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | Jifty->rpc->call( name => "remote-method" ); | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | L<Jifty::Plugin::PubSub> interfaces with an L<AnyEvent::RabbitMQ> | ||
| 18 | connection to provide a message bus. This provides C<Jifty->rpc> which | ||
| 19 | implements an L<AnyEvent::RabbitMQ::RPC> using that connection; see that | ||
| 20 | module for complete documentation. | ||
| 21 | |||
| 22 | =head1 METHODS | ||
| 23 | |||
| 24 | =head2 prereq_plugins | ||
| 25 | |||
| 26 | Use of this plugin requires (or implicitly loads, if missing) the | ||
| 27 | L<Jifty::Plugin::PubSub> plugin. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | use AnyEvent::RabbitMQ::RPC; | ||
| 32 | |||
| 33 | sub prereq_plugins { 'PubSub' } | ||
| 34 | |||
| 35 | our $VERSION = '0.5'; | ||
| 36 | |||
| 37 | =head2 init | ||
| 38 | |||
| 39 | This plugin has one configuration option, C<serialize>, which defaults | ||
| 40 | to C<Storable>. See L<AnyEvent::RabbitMQ::RPC> for documentation on the | ||
| 41 | possible alternatives. | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | our $RPC; | ||
| 46 | sub init { | ||
| 47 | my $self = shift; | ||
| 48 | my %opt = ( | ||
| 49 | serialize => "Storable", | ||
| 50 | @_, | ||
| 51 | ); | ||
| 52 | |||
| 53 | $RPC = AnyEvent::RabbitMQ::RPC->new( | ||
| 54 | serialize => $opt{serialize}, | ||
| 55 | connection => Jifty->bus->_rf, | ||
| 56 | ); | ||
| 57 | |||
| 58 | *Jifty::rpc = sub { $RPC }; | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; |