当前位置: 动力学知识库 > 问答 > 编程问答 >

perl - Examples from Net::RabbitMQ not working

问题描述:

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.

网友答案:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: