Skip to content

Commit

Permalink
Make explicit options override those supplied in a URL. Tidy up example.
Browse files Browse the repository at this point in the history
  • Loading branch information
squaremo committed Jul 19, 2011
1 parent 735160f commit 21d38e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -58,7 +58,7 @@ The options object has the these defaults:

All of these can be passed in a single URL of the form

amqp[s]://[[user:password@]hostname[:port]/vhost
amqp[s]://[user:password@]hostname[:port][/vhost]

Note that the vhost must be URL-encoded and appear as the only segment
of the path, i.e., there is only the leading slash; leaving the path
Expand All @@ -68,7 +68,10 @@ be used (it could also be supplied as the path `/%2f`).
This URL is supplied as the field `url` in the options; for example

var conn =
amqp.createConnection({url: "amqp://guest:guest@localhost:5672/%2f"});
amqp.createConnection({url: "amqp://guest:guest@localhost:5672"});

Options provided as individual fields will override values given in
the URL.

After a connection is established the `'connect'` event is fired as it is
with any `net.Connection` instance. AMQP requires a 7-way handshake which
Expand Down
6 changes: 3 additions & 3 deletions amqp.js
Expand Up @@ -880,7 +880,7 @@ function urlOptions(connectionString) {
}
opts.ssl = ('amqps' === scheme);
opts.host = url.hostname;
opts.port = url.port || defaultPorts[url.scheme]
opts.port = url.port || defaultPorts[scheme]
if (url.auth) {
var auth = url.auth.split(':');
auth[0] && (opts.login = auth[0]);
Expand All @@ -901,8 +901,8 @@ exports.createConnection = function (options) {

Connection.prototype.setOptions = function (options) {
var o = {};
mixin(o, defaultOptions, options || {});
if (o['url']) mixin(o, urlOptions(o['url']));
urlo = (options && options.url) ? urlOptions(options.url) : {};
mixin(o, defaultOptions, urlo, options || {});
this.options = o;
};

Expand Down

0 comments on commit 21d38e4

Please sign in to comment.