0

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.
4

2 回答 2

1

问题是%qparams需要通过引用而不是直接传递。将第 28 行更改为:

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

解决了我的问题。

于 2014-11-14T13:58:30.187 回答
0

它不会出错。它打印到 STDERR 而不检查是否发生错误。它说我会尝试,然后它会:

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

这只是一个信息,而不是错误。

于 2014-11-14T13:52:52.883 回答