简体   繁体   English

错误:Node.js中的Econn被拒绝

[英]Error: Econn is refused in Node.js

I'm going through a RabbitMQ tutorial in node.js 我正在阅读node.js中的RabbitMQ教程

Every time I run node send.js I keep getting an error saying the econn is refused. 每次我运行node send.js我总是收到一条错误消息,说econn被拒绝。

Here's what my code looks like: 这是我的代码:

var amqp = require('amqplib');
var when = require('when');

amqp.connect('amqp://localhost').then(function(conn){
        return when (conn.createChannel().then(function(ch){
                var q = 'hello';
                var msg= 'Hello World!';

                var ok = ch.assertQueue(q, {durable: false});

                return ok.then(function(_qok){
                        ch.sendToQueue(q, new Buffer(msg));
                        console.log(" [x] Sent '%s'",msg);
                        return ch.close();
                });
        })).ensure(function() {conn.close(); });;
}).then(null,console.warn);

Here's what the error says: 错误显示如下:

  { [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

I'm not sure what I'm doing wrong, or what I need (I'm not too experienced with node.js). 我不确定自己在做什么错或需要什么(我对node.js不太了解)。 But I'm pretty sure it has something to do with the localhost server. 但是我很确定它与本地服务器有关。 I tried googling and searching on here at stackoverflow, but nothing that I could find to my use. 我尝试使用Google谷歌搜索并在stackoverflow上进行搜索,但没有找到我可以使用的东西。

You need to start RabbitMQ-server before connecting. 在连接之前,您需要启动RabbitMQ服务器。 If you installed RabbitMQ as a system package in Linux, issue: 如果您在Linux中将RabbitMQ安装为系统软件包,请发出:

sudo service rabbitmq-server start

If you downloaded and unpacked it somewhere (any OS), then launch the rabbitmq-server script you will found in the sbin/ subdirectory. 如果在某个地方(任何操作系统)下载并解压缩了该文件,请启动sbin/子目录中的rabbitmq-server脚本。

If you did not download the server, then get the appropriate package from RabbitMQ download page . 如果您没有下载服务器,请从RabbitMQ下载页面获取相应的软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM