Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve perl tutorial files.

Fixed a few spelling errors. Removed unnecessary timeout argument from
some connections. Removed on_return callback from send.pl. Modified
rpc_client to allow parameter passing. Added autoflush, $|++, to allow
for automated testing.
  • Loading branch information...
commit fc06c863ac6750dea6bc0dd86bc431f8105016d0 1 parent a52e816
@Lanzaa Lanzaa authored
View
2  perl/README.md
@@ -7,7 +7,7 @@ To successfully use the examples you will need a running RabbitMQ server.
## Requirements
-To run this code you need to intall Net::RabbitFoot.
+To run this code you need to install Net::RabbitFoot.
cpan -i Net::RabbitFoot
View
3  perl/emit_log.pl
@@ -3,10 +3,9 @@
use strict;
use warnings;
+$|++;
use Net::RabbitFoot;
-use Data::Dumper;
-
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
port => 5672,
View
1  perl/emit_log_direct.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+$|++;
use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
View
3  perl/emit_log_topic.pl
@@ -3,8 +3,9 @@
use strict;
use warnings;
-use Net::RabbitFoot;
+$|++;
use AnyEvent;
+use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
View
2  perl/new_task.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+$|++;
use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
@@ -11,7 +12,6 @@
user => 'guest',
pass => 'guest',
vhost => '/',
- timeout => 1,
);
View
5 perl/receive.pl
@@ -3,8 +3,9 @@
use strict;
use warnings;
-use Net::RabbitFoot;
+$|++;
use AnyEvent;
+use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
@@ -23,7 +24,7 @@
sub callback {
my $var = shift;
my $body = $var->{body}->{payload};
- print " [X] Recevied $body\n";
+ print " [x] Received $body\n";
}
$ch->consume(
View
1  perl/receive_logs.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+$|++;
use AnyEvent;
use Net::RabbitFoot;
View
1  perl/receive_logs_direct.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+$|++;
use AnyEvent;
use Net::RabbitFoot;
View
3  perl/receive_logs_topic.pl
@@ -3,8 +3,9 @@
use strict;
use warnings;
-use Net::RabbitFoot;
+$|++;
use AnyEvent;
+use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
View
83 perl/rpc_client.pl
@@ -3,52 +3,55 @@
use strict;
use warnings;
-use Net::RabbitFoot;
+$|++;
use AnyEvent;
+use Net::RabbitFoot;
use UUID::Tiny;
-use Data::Dumper;
-
-my $cv = AnyEvent->condvar;
-my $corr_id = UUID::Tiny::create_UUID_as_string(UUID::Tiny::UUID_V4);
-
-my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
- host => 'localhost',
- port => 5672,
- user => 'guest',
- pass => 'guest',
- vhost => '/',
-);
-
-my $channel = $conn->open_channel();
-
-my $result = $channel->declare_queue(exclusive => 1);
-my $callback_queue = $result->{method_frame}->{queue};
-
-sub on_response {
- my $var = shift;
- my $body = $var->{body}->{payload};
- if ($corr_id eq $var->{header}->{correlation_id}) {
- $cv->send($body);
+sub fibonacci_rpc($) {
+ my $n = shift;
+ my $cv = AnyEvent->condvar;
+ my $corr_id = UUID::Tiny::create_UUID_as_string(UUID::Tiny::UUID_V4);
+
+ my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
+ host => 'localhost',
+ port => 5672,
+ user => 'guest',
+ pass => 'guest',
+ vhost => '/',
+ );
+
+ my $channel = $conn->open_channel();
+
+ my $result = $channel->declare_queue(exclusive => 1);
+ my $callback_queue = $result->{method_frame}->{queue};
+
+ sub on_response {
+ my $var = shift;
+ my $body = $var->{body}->{payload};
+ if ($corr_id eq $var->{header}->{correlation_id}) {
+ $cv->send($body);
+ }
}
-}
-$channel->consume(
- no_ack => 1,
- on_consume => \&on_response,
-);
-
-$channel->publish(
- exchange => '',
- routing_key => 'rpc_queue',
- header => {
- reply_to => $callback_queue,
- correlation_id => $corr_id,
- },
- body => 30,
-);
+ $channel->consume(
+ no_ack => 1,
+ on_consume => \&on_response,
+ );
+
+ $channel->publish(
+ exchange => '',
+ routing_key => 'rpc_queue',
+ header => {
+ reply_to => $callback_queue,
+ correlation_id => $corr_id,
+ },
+ body => $n,
+ );
+ return $cv->recv;
+}
print " [x] Requesting fib(30)\n";
-my $response = $cv->recv;
+my $response = fibonacci_rpc(30);
print " [.] Got $response\n";
View
5 perl/rpc_server.pl
@@ -3,10 +3,9 @@
use strict;
use warnings;
-use Net::RabbitFoot;
+$|++;
use AnyEvent;
-
-use Data::Dumper;
+use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
View
5 perl/send.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+$|++;
use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
@@ -11,7 +12,6 @@
user => 'guest',
pass => 'guest',
vhost => '/',
- timeout => 1,
);
@@ -21,9 +21,6 @@
exchange => '',
routing_key => 'hello',
body => 'Hello World!',
- on_return => sub {
- print "hello World\n";
- },
);
print " [x] Sent 'Hello World!'\n";
View
1  perl/worker.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+$|++;
use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
Please sign in to comment.
Something went wrong with that request. Please try again.