Skip to content

Commit

Permalink
docs: acknowledge Ben Whatley's addition of remove bindings feature 👏
Browse files Browse the repository at this point in the history
  • Loading branch information
arobson committed Feb 10, 2018
1 parent fc4bb31 commit d89e867
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 181 deletions.
1 change: 1 addition & 0 deletions ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Several folks have contributed time, effort, ideas or small PRs to this project. It would not be what it is without them!

* [Ryan Niemeyer](http://knockmeout.net)
* [Ben Whatley](https://github.com/darklordzw)
* [Randy Groff](http://randygroff.com)
* [Joseph Frazier](https://github.com/josephfrazier)
* [Sean Corrales](https://github.com/droidenator)
Expand Down
272 changes: 136 additions & 136 deletions spec/behavior/topology.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,49 +571,49 @@ describe('Topology', function () {
topology.definitions.bindings[ 'from->to' ].should.eql({ source: 'from', target: 'to' });
});
});
describe( "when removing an exchange to exchange binding with no keys", function() {
var topology, conn, ex, q;

before( function() {
ex = emitter();
q = emitter();
var Exchange = function() {
return ex;
};
var Queue = function() {
return q;
};
conn = connectionFn();
var control = {
bindExchange: noOp,
bindQueue: noOp,
unbindQueue: noOp,
unbindExchange: noOp
};
var controlMock = sinon.mock( control );
controlMock
.expects( "bindExchange" )
.once()
.withArgs( "to", "from", '' )
.returns( when.resolve() );
controlMock
.expects( "unbindExchange" )
.once()
.withArgs( "to", "from", '' )
.returns( when.resolve() );
conn.mock.expects( "getChannel" )
.twice()
.resolves( control );
topology = topologyFn( conn.instance, {}, {}, undefined, undefined, Exchange, Queue );
return topology.createBinding( { source: "from", target: "to" } )
.then(topology.removeBinding( { source: "from", target: "to" } ));
} );

it( "should remove binding from definitions", function() {
should.not.exist(topology.definitions.bindings[ "from->to" ]);
} );
} );

describe('when removing an exchange to exchange binding with no keys', function () {
var topology, conn, ex, q;

before(function () {
ex = emitter();
q = emitter();
var Exchange = function () {
return ex;
};
var Queue = function () {
return q;
};
conn = connectionFn();
var control = {
bindExchange: noOp,
bindQueue: noOp,
unbindQueue: noOp,
unbindExchange: noOp
};
var controlMock = sinon.mock(control);
controlMock
.expects('bindExchange')
.once()
.withArgs('to', 'from', '')
.returns(Promise.resolve());
controlMock
.expects('unbindExchange')
.once()
.withArgs('to', 'from', '')
.returns(Promise.resolve());
conn.mock.expects('getChannel')
.twice()
.resolves(control);
topology = topologyFn(conn.instance, {}, {}, undefined, undefined, Exchange, Queue);
return topology.createBinding({ source: 'from', target: 'to' })
.then(topology.removeBinding({ source: 'from', target: 'to' }));
});

it('should remove binding from definitions', function () {
should.not.exist(topology.definitions.bindings[ 'from->to' ]);
});
});

describe('when creating an exchange to queue binding with no keys', function () {
var topology, conn, ex, q;
Expand Down Expand Up @@ -654,53 +654,53 @@ describe('Topology', function () {
);
});
});
describe( "when removing an exchange to queue binding with no keys", function() {
var topology, conn, ex, q;

before( function() {
ex = emitter();
q = emitter();
var Exchange = function() {
return ex;
};
var Queue = function() {
return q;
};
conn = connectionFn();
var control = {
bindExchange: noOp,
bindQueue: noOp,
unbindExchange: noOp,
unbindQueue: noOp
};
var controlMock = sinon.mock( control );
controlMock.expects( "bindQueue" )
.withArgs( "to", "from", "a.*" )
.returns( when.resolve() );
controlMock.expects( "bindQueue" )
.withArgs( "to", "from", "b.*" )
.returns( when.resolve() );
controlMock.expects( "unbindQueue" )
.withArgs( "to", "from", "a.*" )
.returns( when.resolve() );
controlMock.expects( "unbindQueue" )
.withArgs( "to", "from", "b.*" )
.returns( when.resolve() );

conn.mock.expects( "getChannel" )
.twice()
.resolves( control );
topology = topologyFn( conn.instance, {}, {}, undefined, undefined, Exchange, Queue );
topology.createBinding( { source: "from", target: "to", keys: undefined, queue: true } )
.catch( _.noop )
.then(topology.removeBinding( { source: "from", target: "to" } ));
} );

it( "should remove binding from definitions", function() {
should.not.exist(topology.definitions.bindings[ "from->to" ]);
} );
} );

describe('when removing an exchange to queue binding with no keys', function () {
var topology, conn, ex, q;

before(function () {
ex = emitter();
q = emitter();
var Exchange = function () {
return ex;
};
var Queue = function () {
return q;
};
conn = connectionFn();
var control = {
bindExchange: noOp,
bindQueue: noOp,
unbindExchange: noOp,
unbindQueue: noOp
};
var controlMock = sinon.mock(control);
controlMock.expects('bindQueue')
.withArgs('to', 'from', 'a.*')
.returns(Promise.resolve());
controlMock.expects('bindQueue')
.withArgs('to', 'from', 'b.*')
.returns(Promise.resolve());
controlMock.expects('unbindQueue')
.withArgs('to', 'from', 'a.*')
.returns(Promise.resolve());
controlMock.expects('unbindQueue')
.withArgs('to', 'from', 'b.*')
.returns(Promise.resolve());

conn.mock.expects('getChannel')
.twice()
.resolves(control);
topology = topologyFn(conn.instance, {}, {}, undefined, undefined, Exchange, Queue);
topology.createBinding({ source: 'from', target: 'to', keys: undefined, queue: true })
.catch(_.noop)
.then(topology.removeBinding({ source: 'from', target: 'to' }));
});

it('should remove binding from definitions', function () {
should.not.exist(topology.definitions.bindings[ 'from->to' ]);
});
});

describe('when creating an exchange to queue binding with keys', function () {
var topology, conn, ex, q;
Expand Down Expand Up @@ -739,52 +739,52 @@ describe('Topology', function () {
{ source: 'from', target: 'to', keys: [ 'a.*', 'b.*' ], queue: true }
);
});
describe( "when removing an exchange to queue binding with keys", function() {
var topology, conn, ex, q;

before( function() {
ex = emitter();
q = emitter();
var Exchange = function() {
return ex;
};
var Queue = function() {
return q;
};
conn = connectionFn();
var control = {
bindExchange: noOp,
bindQueue: noOp,
unbindExchange: noOp,
unbindQueue: noOp
};
var controlMock = sinon.mock( control );
controlMock.expects( "bindQueue" )
.withArgs( "to", "from", "a.*" )
.returns( when.resolve() );
controlMock.expects( "bindQueue" )
.withArgs( "to", "from", "b.*" )
.returns( when.resolve() );
controlMock.expects( "unbindQueue" )
.withArgs( "to", "from", "a.*" )
.returns( when.resolve() );
controlMock.expects( "unbindQueue" )
.withArgs( "to", "from", "b.*" )
.returns( when.resolve() );

conn.mock.expects( "getChannel" )
.twice()
.resolves( control );
topology = topologyFn( conn.instance, {}, {}, undefined, undefined, Exchange, Queue );
topology.createBinding( { source: "from", target: "to", keys: [ "a.*", "b.*" ], queue: true } )
.then(topology.removeBinding( { source: "from", target: "to" } ));
} );

it( "should remove binding from definitions", function() {
should.not.exist(topology.definitions.bindings[ "from->to" ]);
} );
} );

describe('when removing an exchange to queue binding with keys', function () {
var topology, conn, ex, q;

before(function () {
ex = emitter();
q = emitter();
var Exchange = function () {
return ex;
};
var Queue = function () {
return q;
};
conn = connectionFn();
var control = {
bindExchange: noOp,
bindQueue: noOp,
unbindExchange: noOp,
unbindQueue: noOp
};
var controlMock = sinon.mock(control);
controlMock.expects('bindQueue')
.withArgs('to', 'from', 'a.*')
.returns(Promise.resolve());
controlMock.expects('bindQueue')
.withArgs('to', 'from', 'b.*')
.returns(Promise.resolve());
controlMock.expects('unbindQueue')
.withArgs('to', 'from', 'a.*')
.returns(Promise.resolve());
controlMock.expects('unbindQueue')
.withArgs('to', 'from', 'b.*')
.returns(Promise.resolve());

conn.mock.expects('getChannel')
.twice()
.resolves(control);
topology = topologyFn(conn.instance, {}, {}, undefined, undefined, Exchange, Queue);
topology.createBinding({ source: 'from', target: 'to', keys: [ 'a.*', 'b.*' ], queue: true })
.then(topology.removeBinding({ source: 'from', target: 'to' }));
});

it('should remove binding from definitions', function () {
should.not.exist(topology.definitions.bindings[ 'from->to' ]);
});
});
});

describe('when a connection to rabbit cannot be established', function () {
Expand Down
20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,16 @@ Broker.prototype.stopSubscription = function (queueName, connectionName = DEFAUL
throw new Error("No queue named '" + queueName + "' for connection '" + connectionName + "'. Unsubscribe failed.");
}
};
Broker.prototype.unbindExchange = function( source, target, keys, connectionName = DEFAULT ) {
return this.connections[ connectionName ].removeBinding( { source: source, target: target, keys: keys } );
};
Broker.prototype.unbindQueue = function( source, target, keys, connectionName = DEFAULT ) {
return this.connections[ connectionName ].removeBinding(
{ source: source, target: target, keys: keys, queue: true },
connectionName
);

Broker.prototype.unbindExchange = function (source, target, keys, connectionName = DEFAULT) {
return this.connections[ connectionName ].removeBinding({ source: source, target: target, keys: keys });
};

Broker.prototype.unbindQueue = function (source, target, keys, connectionName = DEFAULT) {
return this.connections[ connectionName ].removeBinding(
{ source: source, target: target, keys: keys, queue: true },
connectionName
);
};

require('./config.js')(Broker);
Expand Down
Loading

0 comments on commit d89e867

Please sign in to comment.