forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive_logs.pl
49 lines (36 loc) · 839 Bytes
/
receive_logs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
use strict;
use warnings;
$|++;
use AnyEvent;
use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
port => 5672,
user => 'guest',
pass => 'guest',
vhost => '/',
);
my $channel = $conn->open_channel();
$channel->declare_exchange(
exchange => 'logs',
type => 'fanout',
);
my $result = $channel->declare_queue( exclusive => 1, );
my $queue_name = $result->{method_frame}->{queue};
$channel->bind_queue(
exchange => 'logs',
queue => $queue_name,
);
print " [*] Waiting for logs. To exit press CTRL-C\n";
sub callback {
my $var = shift;
my $body = $var->{body}->{payload};
print " [x] $body\n";
}
$channel->consume(
on_consume => \&callback,
queue => $queue_name,
no_ack => 1,
);
AnyEvent->condvar->recv;