Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NOT_FOUND - no queue 'node-topic-queue-one' in vhost '/'

I have Made a simple app that send message to the client via RabbitMQ server. For that I have created sender side code as below.

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);
 });

and my receiver side code is as shown below:

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);
});

problem is that..it gives an error like that

D:\node example\RabbitMQ Example>node worker1.js an error

Error: NOT_FOUND - no exchange 'node-topic-exchange' in vhost '/' an error Error: read ECONNRESET

please help to solve this out.....

like image 528
Nitin Bhanderi Avatar asked Nov 19 '25 19:11

Nitin Bhanderi


1 Answers

You need to use node.js event driven approach: "An exchange will emit the 'open' event when it is finally declared." - the exchange is not declared yet when you try to use it.

On the receiver side you need to do the same for the exchange and for the queue: "A queue will call the callback given to the connection.queue() method once it is usable"

For completeness I report the example here:

var q = connection.queue('my-queue', function (queue) {
  console.log('Queue ' + queue.name + ' is open');
});
like image 135
Sigi Avatar answered Nov 22 '25 08:11

Sigi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!