forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.pl
46 lines (34 loc) · 748 Bytes
/
worker.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
#!/usr/bin/perl
use strict;
use warnings;
$|++;
use Net::RabbitFoot;
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
host => 'localhost',
port => 5672,
user => 'guest',
pass => 'guest',
vhost => '/',
);
my $ch = $conn->open_channel();
$ch->declare_queue(
queue => 'task_queue',
durable => 1,
);
print " [*] Waiting for messages. To exit press CTRL-C\n";
sub callback {
my $var = shift;
my $body = $var->{body}->{payload};
print " [x] Received $body\n";
my @c = $body =~ /\./g;
sleep(scalar(@c));
print " [x] Done\n";
$ch->ack();
}
$ch->qos(prefetch_count => 1,);
$ch->consume(
on_consume => \&callback,
no_ack => 0,
);
# Wait forever
AnyEvent->condvar->recv;