From 21d38e42e03bf8221c2f8ac8ae6fea780f330f90 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 19 Jul 2011 15:34:11 +0100 Subject: [PATCH] Make explicit options override those supplied in a URL. Tidy up example. --- README.md | 7 +++++-- amqp.js | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98d4795..4e06dfc 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/amqp.js b/amqp.js index 866b828..7b260ca 100644 --- a/amqp.js +++ b/amqp.js @@ -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]); @@ -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; };