Skip to content

Commit 6d51995

Browse files
authored
Merge pull request #31 from msgflo/amqp-removebinding
AMQP: Implement removeBinding()
2 parents c76fdd2 + 7871578 commit 6d51995

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

spec/01transport.coffee

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,48 @@ transportTests = (type) ->
203203
clients.sender.sendTo 'outqueue', outQueue, payload, (err) ->
204204
chai.expect(err).to.be.a 'null'
205205

206+
describe 'outqueue bound to inqueue then removed', ->
207+
it 'sending to inqueue, show up on outqueue', (done) ->
208+
payload = { foo: 'bar922' }
209+
inQueue = 'inqueue922'
210+
outQueue = 'outqueue922'
211+
createConnectClients address, ['sender', 'receiver'], (err, clients) ->
212+
createQueues [
213+
[ clients.receiver, 'inqueue', inQueue ]
214+
[ clients.sender, 'outqueue', outQueue ]
215+
], (err) ->
216+
chai.expect(err).to.not.exist
217+
218+
binding = { type:'pubsub', src:outQueue, tgt:inQueue }
219+
bindingRemoved = false
220+
221+
onReceive = (msg) ->
222+
if bindingRemoved
223+
done new Error "Received data on removed binding"
224+
done = null
225+
return
226+
227+
clients.receiver.ackMessage msg
228+
chai.expect(msg).to.include.keys 'data'
229+
chai.expect(msg.data).to.eql payload
230+
bindingRemoved = true
231+
broker.removeBinding binding, (err) ->
232+
chai.expect(err).to.be.a 'null'
233+
clients.sender.sendTo 'outqueue', outQueue, payload, (err) ->
234+
chai.expect(err).to.be.a 'null'
235+
setTimeout () ->
236+
done null if done
237+
done = null
238+
return
239+
, 300
240+
241+
clients.receiver.subscribeToQueue inQueue, onReceive, (err) ->
242+
chai.expect(err).to.be.a 'null'
243+
broker.addBinding binding, (err) ->
244+
chai.expect(err).to.be.a 'null'
245+
clients.sender.sendTo 'outqueue', outQueue, payload, (err) ->
246+
chai.expect(err).to.be.a 'null'
247+
206248

207249
describe 'multiple outqueues bound to one inqueue', ->
208250
it 'all sent on outqueues shows up on inqueue', (done) ->

src/amqp.coffee

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ class MessageBroker extends Client
197197
return callback err
198198

199199
addBinding: (binding, callback) ->
200-
# TODO: support roundrobin type
201200
debug 'Broker.addBinding', binding
202201
if binding.type == 'pubsub'
203202
@channel.bindQueue binding.tgt, binding.src, '', {}, callback
@@ -234,9 +233,18 @@ class MessageBroker extends Client
234233
else
235234
return callback new Error 'Unsupported binding type: '+binding.type
236235

237-
removeBinding: (binding, callback) -> # FIXME: implement
238-
return callback null
236+
removeBinding: (binding, callback) ->
237+
debug 'Broker.removeBinding', binding
238+
if binding.type == 'pubsub'
239+
@channel.unbindQueue binding.tgt, binding.src, '', {}, callback
240+
else if binding.type == 'roundrobin'
241+
return callback new Error "removeBinding() not supported for type='roundrobin'" # TODO:
242+
else
243+
return callback new Error "Unsupported binding type: #{binding.type}"
244+
245+
239246
listBindings: (from, callback) -> # FIXME: implement
247+
# NOTE: probably need to use the RabbitMQ HTTP API for this
240248
return callback null, []
241249

242250
# Data subscriptions

0 commit comments

Comments
 (0)