Node.js 未找到-没有队列';节点主题队列一';在vhost'/';

Node.js 未找到-没有队列';节点主题队列一';在vhost'/';,node.js,rabbitmq,amqp,Node.js,Rabbitmq,Amqp,我制作了一个简单的应用程序,通过RabbitMQ服务器向客户端发送消息。 为此,我创建了发送方端代码,如下所示 var amqp=require('amqp'); var connection = amqp.createConnection({host:'localhost',login:'guest',password:'guest'}); connection.on('ready', function () { // There is no need to declare type,

我制作了一个简单的应用程序,通过RabbitMQ服务器向客户端发送消息。 为此,我创建了发送方端代码,如下所示

var amqp=require('amqp');

var connection = amqp.createConnection({host:'localhost',login:'guest',password:'guest'});

connection.on('ready', function () {
 // There is no need to declare type, 'topic' is the default:

 var exchange = connection.exchange('node-topic-exchange'); 

 console.log("publishing messages");
 exchange.publish("topic_a.subtopic_a", {msg:'First Message'});
 exchange.publish("topic_a.subtopic_b", {msg:'Second Message'});
 exchange.publish("topic_b.subtopic_b", {msg:'Third Message'});
 });

 connection.on('error',function (err) {
  console.log('an error '+err);
 });
我的接收端代码如下所示:

var amqp=require('amqp');
var connection = amqp.createConnection({host:'localhost',login:'guest',password:'guest'}); 
 connection.on('ready', function () {
  // There is no need to declare type, 'topic' is the default:
  var exchange = connection.exchange('node-topic-exchange');
  // Consumer:
  var queue = connection.queue('node-topic-queue-one');
  queue.bind(exchange, "topic_a.*");
  queue.subscribe(function (message) {
  // Get original message string:
  console.log('Message : ' + message.msg);
   });
  });
  connection.on('error',function (err) {
 console.log('an error '+err);
});
问题是……它会产生这样的错误

D:\node example\RabbitMQ example>node worker1.js错误

错误: 未找到-vhost“/”中没有交换“节点主题交换”错误 错误:读取EconReset


请帮助解决此问题。…

您需要使用node.js事件驱动方法:-尝试使用时尚未声明exchange

在接收方,您需要对exchange和队列执行相同的操作:

为完整起见,我在此报告示例:

var q = connection.queue('my-queue', function (queue) {
  console.log('Queue ' + queue.name + ' is open');
});

我想您需要使用node.js事件驱动的方法:“当一个exchange最终声明时,它将发出‘打开’事件。”()-当您尝试使用它时,它还没有声明。它可以工作,,!!但我在接收端也犯了同样的错误…@Sigismondosame story,还有队列!对于其他语言(如java),您需要显式地“声明”交换和队列(即,如果不存在,则创建),为了实现良好的解耦,最好在生产者和消费者身上都这样做。还添加了答案,以便其他人可以发现它有用。谢谢..它可以工作...:)@西吉斯蒙多