Subject: | More Examples |
Could you add a sample consumer to your documentation?
I built the two following scripts to play with this module and rabbitmq
listener.pl:
#!/usr/bin/perl
use strict;
use Data::Dumper;
use Net::RabbitMQ;
my $channel = 1;
my $queue = "MyQueue.q";
my $exchange = "MyExchange.x";
my $routing_key = "foobar";
my $mq = Net::RabbitMQ->new();
$mq->connect("localhost", { user => "guest", password => "guest" });
$mq->channel_open($channel);
$mq->exchange_declare( $channel, $exchange, { auto_delete => 0, });
$mq->queue_declare( $channel, $queue, { auto_delete => 0, });
$mq->queue_bind( $channel, $queue, $exchange, $routing_key);
while(1){
my $hashref = $mq->get($channel, $queue);
next if (! defined($hashref));
print Dumper($hashref);
}
And poster.pl:
#!/usr/bin/perl
my $channel = 1;
my $queue = "MyQueue.q";
my $exchange = "MyExchange.x";
my $routing_key = "foobar";
use Net::RabbitMQ;
my $mq = Net::RabbitMQ->new();
$mq->connect("localhost", { user => "guest", password => "guest" });
$mq->channel_open(1);
$mq->publish($channel, $queue, "Message Here");
$mq->disconnect();
This way a user can just toss the code into two files and see it work.
Thanks for this great module.
--Joe