Skip Menu |

This queue is for tickets about the Net--RabbitMQ CPAN distribution.

Report information
The Basics
Id: 71337
Status: open
Priority: 0/
Queue: Net--RabbitMQ

People
Owner: Nobody in particular
Requestors: bigjoe1008 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: (no value)
Fixed in: (no value)



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
Hi, The receiver example here is not good. Rather than doing a busy-loop, try this: $mq->consume( $channel, $queue); while (1) { my $hashref = $mq->recv; print Dumper($hashref); }