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

amqp.connect() shows unexpected behavior with special character(#) in password #269

Closed
brianjang opened this issue Aug 26, 2016 · 2 comments

Comments

@brianjang
Copy link

amqp.connect('amqp://incowiz:incowiz#1@192.168.0.104', function(err, conn) {
  conn.createChannel(function(err, ch) {
    var q = 'hello';

    ch.assertQueue(q, {durable: false});
    console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
    ch.consume(q, function(msg) {
      console.log(" [x] Received %s", msg.content.toString());
    }, {noAck: true});
  });
});

err object shows the below log message:
err --------------------------------------
{ [Error: getaddrinfo ENOTFOUND incowiz incowiz:5672]
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'incowiz',
host: 'incowiz',

port: 5672 }

/home/brian-pc/workspace/incowiz_push/rabbitmq/01_send.js:10
conn.createChannel(function(err, ch) {
^

@connec
Copy link

connec commented Aug 26, 2016

A plain # in a URL is treated as the fragment/hash separator. Try URL encoding the hash:

amqp.connect('amqp://incowiz:incowiz%231@192.168.0.104', function (err, conn) {
  ...
});

@squaremo
Copy link
Collaborator

Yes indeed, thanks @connec.

@brianjang You can use encodeURIComponent to reliably do this for the password (and username, and virtual host, ...) before constructing the URL. Another option is to use a connection object, as in #159, which means you don't have to encode things.

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

No branches or pull requests

4 participants