Skip to content

Commit c2cfe93

Browse files
committed
Added unbind to the API, wrote a test
1 parent 0430a9e commit c2cfe93

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ Queue.DeclareOk queueDeclare(int ticket, String queue, boolean passive, boolean
296296
*/
297297
Queue.BindOk queueBind(int ticket, String queue, String exchange, String routingKey) throws IOException;
298298

299+
/**
300+
* Uninds a queue from an exchange, with no extra arguments.
301+
* @see com.rabbitmq.client.AMQP.Queue.Unbind
302+
* @see com.rabbitmq.client.AMQP.Queue.UnbindOk
303+
* @param ticket an access ticket for the appropriate realm
304+
* @param queue the name of the queue
305+
* @param exchange the name of the exchange
306+
* @param routingKey the routine key to use for the binding
307+
* @return an unbinding-confirm method if the binding was successfully deleted
308+
* @throws java.io.IOException if an error is encountered
309+
*/
310+
Queue.UnbindOk queueUnbind(int ticket, String queue, String exchange, String routingKey) throws IOException;
311+
299312
/**
300313
* Bind a queue to an exchange.
301314
* @see com.rabbitmq.client.AMQP.Queue.Bind
@@ -310,6 +323,20 @@ Queue.DeclareOk queueDeclare(int ticket, String queue, boolean passive, boolean
310323
*/
311324
Queue.BindOk queueBind(int ticket, String queue, String exchange, String routingKey, Map<String, Object> arguments) throws IOException;
312325

326+
/**
327+
* Unbind a queue from an exchange.
328+
* @see com.rabbitmq.client.AMQP.Queue.Unbind
329+
* @see com.rabbitmq.client.AMQP.Queue.UnbindOk
330+
* @param ticket an access ticket for the appropriate realm
331+
* @param queue the name of the queue
332+
* @param exchange the name of the exchange
333+
* @param routingKey the routine key to use for the binding
334+
* @param arguments other properties (binding parameters)
335+
* @return an unbinding-confirm method if the binding was successfully deleted
336+
* @throws java.io.IOException if an error is encountered
337+
*/
338+
Queue.UnbindOk queueUnbind(int ticket, String queue, String exchange, String routingKey, Map<String, Object> arguments) throws IOException;
339+
313340
/**
314341
* Retrieve a message from a queue using {@link com.rabbitmq.client.AMQP.Basic.Get}
315342
* @see com.rabbitmq.client.AMQP.Basic.Get

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,20 @@ public Queue.BindOk queueBind(int ticket, String queue, String exchange,
524524
false, arguments)).getMethod();
525525
}
526526

527+
/**
528+
* Public API - Unbind a queue from an exchange.
529+
* @see com.rabbitmq.client.AMQP.Queue.Unbind
530+
* @see com.rabbitmq.client.AMQP.Queue.UnbindOk
531+
*/
532+
public Queue.UnbindOk queueUnbind(int ticket, String queue, String exchange,
533+
String routingKey, Map<String, Object> arguments)
534+
throws IOException
535+
{
536+
return (Queue.UnbindOk)
537+
exnWrappingRpc(new Queue.Unbind(ticket, queue, exchange, routingKey,
538+
arguments)).getMethod();
539+
}
540+
527541
/**
528542
* Public API - Bind a queue to an exchange, with no extra arguments.
529543
* @see com.rabbitmq.client.AMQP.Queue.Bind
@@ -535,6 +549,17 @@ public Queue.BindOk queueBind(int ticket, String queue, String exchange, String
535549
return queueBind(ticket, queue, exchange, routingKey, null);
536550
}
537551

552+
/**
553+
* Public API - Unbind a queue from an exchange, with no extra arguments.
554+
* @see com.rabbitmq.client.AMQP.Queue.Unbind
555+
* @see com.rabbitmq.client.AMQP.Queue.UnbindOk
556+
*/
557+
public Queue.UnbindOk queueUnbind(int ticket, String queue, String exchange, String routingKey)
558+
throws IOException
559+
{
560+
return queueUnbind(ticket, queue, exchange, routingKey, null);
561+
}
562+
538563
/**
539564
* Public API - Retrieve a message from a queue using {@link com.rabbitmq.client.AMQP.Basic.Get}
540565
* @see com.rabbitmq.client.AMQP.Basic.Get

test/src/com/rabbitmq/client/test/functional/Routing.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
package com.rabbitmq.client.test.functional;
2727

28-
import java.io.IOException;
29-
28+
import com.rabbitmq.client.AMQP;
3029
import com.rabbitmq.client.GetResponse;
3130

31+
import java.io.IOException;
32+
3233
public class Routing extends BrokerTestCase
3334
{
3435

@@ -119,4 +120,23 @@ public void testDoubleBinding()
119120
checkGet(Q1, true);
120121
checkGet(Q1, false);
121122
}
123+
124+
public void testUnbind() throws Exception {
125+
AMQP.Queue.DeclareOk ok = channel.queueDeclare(ticket);
126+
String queue = ok.getQueue();
127+
128+
String routingKey = "quay";
129+
String x = "amq.direct";
130+
131+
channel.queueBind(ticket, queue, x, routingKey);
132+
channel.basicPublish(ticket, x, routingKey, null, "foobar".getBytes());
133+
checkGet(queue, true);
134+
135+
channel.queueUnbind(ticket, queue, x, routingKey);
136+
137+
channel.basicPublish(ticket, x, routingKey, null, "foobar".getBytes());
138+
checkGet(queue, false);
139+
140+
channel.queueDelete(ticket, queue);
141+
}
122142
}

0 commit comments

Comments
 (0)