Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper way of handling errors in channel set up #95

Closed
jonathanasquier opened this issue Aug 24, 2019 · 2 comments · Fixed by #167
Closed

Proper way of handling errors in channel set up #95

jonathanasquier opened this issue Aug 24, 2019 · 2 comments · Fixed by #167
Labels

Comments

@jonathanasquier
Copy link

Hello,
i've seen you've got an empty else statement with a comment // Don't emit an error if setups failed because the channel was closing..
I'm triggering a silent error when I'm trying to re-assert a queue with different arguments (ex: x-dead-letter-exchange)

when I add back the emit block

this.emit("error", err, {
   name: this.name
});

I can get my error

ERROR { Error: Operation failed: QueueDeclare; 406 (PRECONDITION-FAILED) with message "PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'my-queue' in vhost '/': received 'dl_4000' but current is 'dl_3000'"

by listening to the channel error event.
But I guest that was not meant to be done this way, so what would be a proper way of handling error channel setup functions ?

or maybe I'm supposed to catch the error in the disconnected event?

const amqp = require("..");

const connection = amqp.connect(["amqp://localhost"]);
connection.on("connect", function() {
  console.log("Connected!");
});

connection.on("disconnect", function(err) {
  console.log("Disconnected.", err); // got it
});

let channelWrapper = connection.createChannel({
  setup: function(channel) {
    return Promise.all([
      channel.assertQueue("queue_1", {
        durable: true,
        deadLetterExchange: "dl_1"
      })
    ]);
  }
});

channelWrapper.addSetup(channel => {
  return channel.assertQueue("queue_1", {
    deadLetterExchange: "dl_2"
  });
})

(PS: l'm building this https://github.com/trusk-official/amqp-connector and trying to add a deadletter feature!)

Thanks!

@jonathanasquier
Copy link
Author

Closing because stale, i'm using connection.on("disconnect", function(err) {});

luddd3 referenced this issue in luddd3/node-amqp-connection-manager Aug 24, 2021
github-actions bot pushed a commit that referenced this issue Aug 24, 2021
# [3.3.0](v3.2.4...v3.3.0) (2021-08-24)

### Bug Fixes

* emit setup errors not caused by closed channel ([7c5fe10](7c5fe10)), closes [#95](#95)
* setup on channel/connection closing/closed ([b21bd01](b21bd01))

### Features

* immediately reconnect on amqplib connect timeout ([ad06108](ad06108))
@jwalton
Copy link
Owner

jwalton commented Aug 24, 2021

🎉 This issue has been resolved in version 3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants