rabbitmq/rabbitmq-tutorials

Unknown consumer error when using promise based functions (nodejs)

srinivasrk opened this issue · 2 comments

var amqp = require('amqplib');

amqp.connect({
  protocol: 'amqp',
  hostname: `${process.env.RABBITMQ_SERVER}`,
  port: 5672,
  username: 'aaa',
  password: 'aaa',
  locale: 'en_US',
  frameMax: 0,
  heartbeat: 0
}).then((conn) => {
  conn.createChannel().then((ch) => {
    var ex = `logs`;
    ch.assertExchange(ex, 'fanout', {durable : false});

    ch.assertQueue('', {exclusive : true}).then((q) => {
      console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue);
      ch.bindQueue(q.queue, ex, '');
      ch.consume(q.queue).then((msg) => {
        if(msg && msg.content) {
          console.log(" [x] %s", msg.content.toString());
        }
      }, {noAck: true});
    })
  });
})

When I send any data to this exchange it terminates with the following error :

C:\aaa\rabbitmq_examples\exchanges>node receive.js
 [*] Waiting for messages in amq.gen-cZ4ha22XIN2ywA9MydszxQ. To exit press CTRL+C
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: Unknown consumer: amq.ctag-fcY7RlK-dzH0gYvc_fBJ6A
    at Channel.BaseChannel.dispatchMessage (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\channel.js:470:11)
    at Channel.BaseChannel.handleDelivery (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\channel.js:475:15)
    at emitOne (events.js:116:13)
    at Channel.emit (events.js:211:7)
    at C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\channel.js:263:10
    at Channel.content [as handleMessage] (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\channel.js:316:9)
    at Channel.C.acceptMessageFrame (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\channel.js:231:31)
    at Channel.C.accept (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\channel.js:384:17)
    at Connection.mainAccept [as accept] (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\connection.js:64:33)
    at Socket.go (C:\Citilogics\rabbitmq_examples\node_modules\amqplib\lib\connection.js:477:48)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at emitReadable_ (_stream_readable.js:513:10)
    at emitReadable (_stream_readable.js:507:7)
    at addChunk (_stream_readable.js:274:7)
    at readableAddChunk (_stream_readable.js:250:11)

I can see that the queue created and queue consumed is not the same !

Thank you for your time.

Team RabbitMQ uses GitHub issues for specific actionable items engineers can work on. GitHub issues are not used for questions, investigations, root cause analysis, discussions of potential issues, etc (as defined by this team).

We get at least a dozen of questions through various venues every single day, often light on details.
At that rate GitHub issues can very quickly turn into a something impossible to navigate and make sense of even for our team. Because GitHub is a tool our team uses heavily nearly every day, the signal/noise ratio of issues is something we care about a lot.

Please post this to rabbitmq-users.

Thank you.

I'm not a Node.js expert but it sounds like a client-specific issue with variable scopes/shadowing or operation ordering. I cannot reproduce with the tutorial version we have.