diff --git a/lib/amqp_client.js b/lib/amqp_client.js index 01d0fb2..4d71271 100644 --- a/lib/amqp_client.js +++ b/lib/amqp_client.js @@ -188,7 +188,7 @@ AMQPClient.prototype.createSender = function(address, policyOverrides) { throw new Error('Must connect before creating links'); } - address = u.parseLinkAddress(address || this._defaultQueue, this.policy); + address = this.policy.parseLinkAddress(address || this._defaultQueue); policyOverrides = policyOverrides || {}; var linkName = u.linkName(address.name, policyOverrides), @@ -255,7 +255,7 @@ AMQPClient.prototype.createReceiver = function(address, policyOverrides) { throw new Error('Must connect before creating links'); } - address = u.parseLinkAddress(address || this._defaultQueue, this.policy); + address = this.policy.parseLinkAddress(address || this._defaultQueue); policyOverrides = policyOverrides || {}; var linkName = u.linkName(address.name, policyOverrides), @@ -267,9 +267,9 @@ AMQPClient.prototype.createReceiver = function(address, policyOverrides) { } }, policyOverrides, this.policy.receiverLink); - // if the policy supports the defaultSubjects feature, and a subject has been - // provided then automatically set up a filter to match on that subject. - if (this.policy.defaultSubjects && !!address.subject) { + // if a subject has been provided then automatically set up a filter to + // match on that subject. + if (!!address.subject) { if (address.subject === 'undefined' || address.subject === 'null') { throw new errors.InvalidSubjectError(address.subject); } diff --git a/lib/policies/policy.js b/lib/policies/policy.js index 85133a7..f7a12f5 100644 --- a/lib/policies/policy.js +++ b/lib/policies/policy.js @@ -106,6 +106,28 @@ function Policy(overrides) { return Object.seal(this); } +/** + * Parses a link address used for creating Sender and Receiver links. + * + * The resulting object has a required `name` property (used as the source + * address in the attach performative), as well as an optional `subject` property + * which (if specified) will automatically create a source filter. + * + * @param {String} the address to parse + * @return {Object} + */ +Policy.prototype.parseLinkAddress = function(address) { + // @todo: this "parsing" should be far more rigorous + if (!this.defaultSubjects) { + return { name: address }; + } + + var parts = address.split('/'); + var result = { name: parts.shift() }; + if (parts.length) result.subject = parts.shift(); + return result; +}; + /** * Parses an address for use when connecting to an AMQP 1.0 broker * diff --git a/lib/utilities.js b/lib/utilities.js index 9842ff8..ca36f17 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -96,18 +96,6 @@ function bufferEquals(lhs, rhs, offset1, offset2, size) { utilities.bufferEquals = bufferEquals; -// @todo: this "parsing" should be far more rigorous -utilities.parseLinkAddress = function(address, policy) { - if (policy && !policy.defaultSubjects) { - return { name: address }; - } - - var parts = address.split('/'); - var result = { name: parts.shift() }; - if (parts.length) result.subject = parts.shift(); - return result; -}; - function deepMerge() { var args = Array.prototype.slice.call(arguments); var helper = function(tgt, src, key) { diff --git a/test/unit/address.test.js b/test/unit/address.test.js index 8c9773f..6efb8f5 100644 --- a/test/unit/address.test.js +++ b/test/unit/address.test.js @@ -139,7 +139,8 @@ describe('Address Parsing', function() { }); it('should support links with names prefixed with `topic://` and `queue://`', function() { - var address = u.parseLinkAddress('topic://mytopic', ActiveMQPolicy); + var policy = ActiveMQPolicy; + var address = policy.parseLinkAddress('topic://mytopic'); expect(address.name).to.eql('topic://mytopic'); var linkName = u.linkName(address.name, {}); var nonUniqueLinkNamePart = linkName.split('_')[0]; diff --git a/test/unit/test_utilities.js b/test/unit/test_utilities.js index 2434a5a..77480b9 100644 --- a/test/unit/test_utilities.js +++ b/test/unit/test_utilities.js @@ -1,5 +1,6 @@ 'use strict'; -var expect = require('chai').expect, +var Policy = require('../../lib/policies/policy'), + expect = require('chai').expect, u = require('../../lib/utilities'), tu = require('./../testing_utils'); @@ -157,7 +158,8 @@ describe('Utilities', function() { } ].forEach(function(testCase) { it('should match ' + testCase.description, function() { - var result = u.parseLinkAddress(testCase.address); + var policy = new Policy(); + var result = policy.parseLinkAddress(testCase.address); expect(result).to.eql(testCase.expected); }); });