node-bunnymq icon indicating copy to clipboard operation
node-bunnymq copied to clipboard

Error is only printed when using a non existing queue and non existing exchange

Open mrister opened this issue 9 years ago • 2 comments
trafficstars

Example code

  producer.produce('bli:bla',  { msg: Date.now() }, {rpc:false, routingKey: 'my-routing-key'})
      .then(function (rst) {
        console.log('we are done', rst)
      })
      .catch(function(err){
        console.log('err happened', err);
      })

Resolves the produce function (does not reject) but prints this error:

{ Error: Channel closed by server: 404 (NOT-FOUND) with message "NOT_FOUND - no exchange 'bli:bla' in vhost '/'"
   at Channel.C.accept (C:\Users\Harvester\WebstormProjects\Dial-Once\node-bunnymq\node_modules\amqplib\lib\channel.js:406:17)
   at Connection.mainAccept [as accept] (C:\Users\Harvester\WebstormProjects\Dial-Once\node-bunnymq\node_modules\amqplib\lib\connection.js:63:33)
   at Socket.go (C:\Users\Harvester\WebstormProjects\Dial-Once\node-bunnymq\node_modules\amqplib\lib\connection.js:476:48)
   at emitNone (events.js:86:13)
   at Socket.emit (events.js:185:7)
   at emitReadable_ (_stream_readable.js:433:10)
   at emitReadable (_stream_readable.js:427:7)
   at readableAddChunk (_stream_readable.js:188:13)
   at Socket.Readable.push (_stream_readable.js:135:10)
   at TCP.onread (net.js:542:20) code: 404 }

Acceptance

reject the produce function with the error and cover with a test

mrister avatar Jul 19 '16 11:07 mrister

@mrister I have been working on this one for a while and I can't understand how to do so. I checked the error and it is thrown from a channel. So, the reject for this case is quiet simple: this.channel.on('error', reject). But when it comes to resolve, I do not have any event like ack or something. I get the result from checkRpc immediately and it only indicates if the buffer is overflown or not (true/false). Maybe there is something that I am missing? How does the producer know that the message was acknowledged by a consumer?

I currently have something like this:

// produce function
return new Promise((resolve, reject) => {
    return this.conn.get()
    .then((_channel) => {
      this.channel = _channel;
      this.channel.on('error', reject);

      //undefined can't be serialized/buffered :p
      if (!msg) msg = null;

      this.conn.config.transport.info('bmq:producer', '[' + queue + '] > ', msg);

      const result = checkRpc.call(this, queue, parsers.out(msg, options), options);
      resolve(result);
      //this.channel.on('close', () => resolve(result));
    })

The error event is fired before I get the result from checkRpc so it never rejects.

Spring3 avatar Dec 23 '16 23:12 Spring3

@Spring3 amqp is a little bit weird when it comes to nonexistent queues. I think the implementation is ok just that such error should cause a reject like stated in issue. You can look for more information in the amgqp lib we use under the hood for more channel options if you like to. Something like this: http://www.squaremobius.net/amqp.node/channel_api.html#channel_ack More about RabbitMq and RPC here: https://www.rabbitmq.com/tutorials/tutorial-six-javascript.html

mrister avatar Jan 02 '17 15:01 mrister