Examples from Net::RabbitMQ not working

595 views Asked by At

I'm trying to learn RabbitMQ for a project I'm working on. My research showed two libraries to use, Net::RabbitMQ and AnyEvent::RabbitMQ. AnyEvent::RabbitMQ seems overly baroque for my needs but Net::RabbitMQ does not appear to work as the examples show it should. Below is some example code I found, it matches what I saw in the POD, but it isn't working.

#!/usr/bin/env perl
use strict;
use warnings;

use Net::RabbitMQ;

{

    # closure to return a new channel ID every time we call nextchan
    my $nextchan = 1;
    sub nextchan { return $nextchan++ }
}

### BEGIN CONFIGURABLE PARAMETERS ######################################
my $qserver = q{xx.xx.xx.xx};
my %qparms  = ();

my $qname   = q{gravity.checks};
my $message = q{Test injection};
### NO CONFIGURABLE PARAMETERS BELOW THIS LINE #########################

my $mq     = Net::RabbitMQ->new();
my $chanID = nextchan();
$message .= " " . scalar(localtime);

print STDERR qq{Will try to send message "$message" through channel $chanID};

$mq->connect( $qserver, %qparms );

It errors out :

  $. / send . pl
  Will try to send message "Test injection Fri Nov 14 06:50:44 2014" through channel 1 Usage : Net::RabbitMQ::connect( conn, hostname, options ) at . /send.pl line 28.
2

There are 2 answers

0
SparkeyG On BEST ANSWER

The problem is that the %qparams need to be passed by reference and not directly. The change line 28 to :

$mq->connect($qserver, \%qparms) ;

Solved my problem.

2
Ted Bear On

It doesn't error out. It prints to STDERR without checking if an error occured. It says I'll try and then it does:

$mq->connect( $qserver, %qparms );

This is just an information, not an error.