Skip to content

Commit

Permalink
feat: Allow using URL object to connect, same format as amqplib accepts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Walton committed Dec 6, 2019
1 parent 16fd97c commit f046680
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/AmqpConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ export default class AmqpConnectionManager extends EventEmitter {
let amqpUrl = null;

if(typeof urlString === "object") {
amqpUrl = url;
amqpUrl = Object.assign({}, url);
if(!amqpUrl.heartbeat) {
amqpUrl.heartbeat = this.heartbeatIntervalInSeconds;
}
}else {
amqpUrl = urlUtils.parse(urlString);
if(amqpUrl.search) {
Expand Down
23 changes: 23 additions & 0 deletions test/AmqpConnectionManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ describe('AmqpConnectionManager', function() {
})
);

it('should establish a connection to a broker, using an object as the URL', () =>
new Promise(function(resolve, reject) {
amqp = new AmqpConnectionManager({
protocol: 'amqp',
hostname: 'localhost'
});
return amqp.on('connect', ({ connection, url }) =>
Promise.resolve()
.then(() => {
expect(url, 'url').to.eql({
protocol: 'amqp',
hostname: 'localhost'
});
expect(connection.url, 'connection.url').to.eql({
protocol: 'amqp',
hostname: 'localhost',
heartbeat: 5
});
}).then(resolve, reject)
);
})
);

it('should establish a url object based connection to a broker', () =>
new Promise(function(resolve, reject) {
amqp = new AmqpConnectionManager({url: 'amqp://localhost'});
Expand Down

0 comments on commit f046680

Please sign in to comment.