Skip to content
Permalink
Newer
Older
100755 57 lines (47 sloc) 1.36 KB
Oct 13, 2017
1
#!/usr/local/bin/perl -w
2
#
3
# receive_from_queue.pl, DESCRIPTION
4
#
5
# Copyright (C) 2017 Tom Jordan
6
#
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; either version 2
10
# of the License, or (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# $Id:$
18
# Tom Jordan <tom.jordan@wisc.edu>
19
20
use vars qw/$VERSION $FILE/;
21
($VERSION) = q$Revision: 1.1 $ =~ /([\d.]+)/;
22
($FILE) = q$RCSfile: receive_from_queue.pl,v $ =~ /^[^:]+: ([^\$]+),v $/;
23
24
use strict;
25
use warnings;
26
27
$|++;
28
use AnyEvent;
29
use Net::RabbitFoot;
30
31
my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
32
host => 'tier-demo-rabbit',
33
port => 5672,
34
user => 'guest',
35
pass => 'guest',
36
vhost => '/',
37
);
38
39
my $ch = $conn->open_channel();
40
41
$ch->declare_queue(queue => 'TIER101');
42
43
print " [*] Waiting for messages. To exit press CTRL-C\n";
44
45
sub callback {
46
my $var = shift;
47
my $body = $var->{body}->{payload};
48
print " [x] Received $body\n";
49
}
50
51
$ch->consume(
52
on_consume => \&callback,
53
no_ack => 1,
54
);
55
56
# Wait forever
57
AnyEvent->condvar->recv;
You can’t perform that action at this time.