Skip to content

Commit 50fa884

Browse files
Introduce Channel#queueDeclareNowait and #exchangeDeclareNowait
1 parent 8dbfc35 commit 50fa884

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,28 @@ Exchange.DeclareOk exchangeDeclare(String exchange,
343343
boolean internal,
344344
Map<String, Object> arguments) throws IOException;
345345

346+
/**
347+
* Like {@link Channel#exchangeDeclare(String, String, boolean, boolean, java.util.Map)} but
348+
* sets nowait parameter to true and returns nothing (as there will be no response from
349+
* the server).
350+
*
351+
* @param exchange the name of the exchange
352+
* @param type the exchange type
353+
* @param durable true if we are declaring a durable exchange (the exchange will survive a server restart)
354+
* @param autoDelete true if the server should delete the exchange when it is no longer in use
355+
* @param internal true if the exchange is internal, i.e. can't be directly
356+
* published to by a client.
357+
* @param arguments other properties (construction arguments) for the exchange
358+
* @return a declaration-confirm method to indicate the exchange was successfully declared
359+
* @throws java.io.IOException if an error is encountered
360+
*/
361+
void exchangeDeclareNowait(String exchange,
362+
String type,
363+
boolean durable,
364+
boolean autoDelete,
365+
boolean internal,
366+
Map<String, Object> arguments) throws IOException;
367+
346368
/**
347369
* Declare an exchange passively; that is, check if the named exchange exists.
348370
* @param name check the existence of an exchange named this
@@ -446,6 +468,19 @@ Exchange.DeclareOk exchangeDeclare(String exchange,
446468
Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,
447469
Map<String, Object> arguments) throws IOException;
448470

471+
/**
472+
* Like {@link Channel#queueDeclare(String, boolean, boolean, boolean, java.util.Map)} but sets nowait
473+
* flag to true and returns no result (as there will be no response from the server).
474+
* @param queue the name of the queue
475+
* @param durable true if we are declaring a durable queue (the queue will survive a server restart)
476+
* @param exclusive true if we are declaring an exclusive queue (restricted to this connection)
477+
* @param autoDelete true if we are declaring an autodelete queue (server will delete it when no longer in use)
478+
* @param arguments other properties (construction arguments) for the queue
479+
* @throws java.io.IOException if an error is encountered
480+
*/
481+
void queueDeclareNowait(String queue, boolean durable, boolean exclusive, boolean autoDelete,
482+
Map<String, Object> arguments) throws IOException;
483+
449484
/**
450485
* Declare a queue passively; i.e., check if it exists. In AMQP
451486
* 0-9-1, all arguments aside from nowait are ignored; and sending

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,24 @@ public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
664664
arguments);
665665
}
666666

667+
public void exchangeDeclareNowait(String exchange,
668+
String type,
669+
boolean durable,
670+
boolean autoDelete,
671+
boolean internal,
672+
Map<String, Object> arguments) throws IOException {
673+
transmit(new AMQCommand(new Exchange.Declare.Builder()
674+
.exchange(exchange)
675+
.type(type)
676+
.durable(durable)
677+
.autoDelete(autoDelete)
678+
.internal(internal)
679+
.arguments(arguments)
680+
.passive(false)
681+
.nowait(true)
682+
.build()));
683+
}
684+
667685
/** Public API - {@inheritDoc} */
668686
public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
669687
boolean durable,
@@ -794,6 +812,23 @@ public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclare()
794812
return queueDeclare("", false, true, true, null);
795813
}
796814

815+
/** Public API - {@inheritDoc} */
816+
public void queueDeclareNowait(String queue,
817+
boolean durable,
818+
boolean exclusive,
819+
boolean autoDelete,
820+
Map<String, Object> arguments) throws IOException {
821+
transmit(new AMQCommand(new Queue.Declare.Builder()
822+
.queue(queue)
823+
.durable(durable)
824+
.exclusive(exclusive)
825+
.autoDelete(autoDelete)
826+
.arguments(arguments)
827+
.passive(false)
828+
.nowait(true)
829+
.build()));
830+
}
831+
797832
/** Public API - {@inheritDoc} */
798833
public Queue.DeclareOk queueDeclarePassive(String queue)
799834
throws IOException

src/com/rabbitmq/client/impl/recovery/AutorecoveringChannel.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ public AMQP.Exchange.DeclareOk exchangeDeclare(String exchange, String type, boo
190190
return ok;
191191
}
192192

193+
@Override
194+
public void exchangeDeclareNowait(String exchange, String type, boolean durable, boolean autoDelete, boolean internal, Map<String, Object> arguments) throws IOException {
195+
delegate.exchangeDeclareNowait(exchange, type, durable, autoDelete, internal, arguments);
196+
}
197+
193198
public AMQP.Exchange.DeclareOk exchangeDeclarePassive(String name) throws IOException {
194199
return delegate.exchangeDeclarePassive(name);
195200
}
@@ -240,6 +245,14 @@ public AMQP.Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean
240245
return ok;
241246
}
242247

248+
public void queueDeclareNowait(String queue,
249+
boolean durable,
250+
boolean exclusive,
251+
boolean autoDelete,
252+
Map<String, Object> arguments) throws IOException {
253+
delegate.queueDeclareNowait(queue, durable, exclusive, autoDelete, arguments);
254+
}
255+
243256
public AMQP.Queue.DeclareOk queueDeclarePassive(String queue) throws IOException {
244257
return delegate.queueDeclarePassive(queue);
245258
}

test/src/com/rabbitmq/client/test/BrokerTestCase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.rabbitmq.client.test;
1919

2020
import java.io.IOException;
21+
import java.util.UUID;
2122

2223
import junit.framework.TestCase;
2324

@@ -263,4 +264,12 @@ protected void unblock() throws IOException, InterruptedException {
263264
Host.rabbitmqctl("set_vm_memory_high_watermark 0.4");
264265
clearResourceAlarm("disk");
265266
}
267+
268+
protected String generateQueueName() {
269+
return "queue" + UUID.randomUUID().toString();
270+
}
271+
272+
protected String generateExchangeName() {
273+
return "exchange" + UUID.randomUUID().toString();
274+
}
266275
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ public void testExchangeToExchangeBindingRecovery() throws IOException, Interrup
187187
}
188188
}
189189

190-
private String generateExchangeName() {
191-
return "java-client.test.recovery." + UUID.randomUUID().toString();
192-
}
193-
194190
public void testThatDeletedQueueBindingsDontReappearOnRecovery() throws IOException, InterruptedException {
195191
String q = channel.queueDeclare("", false, false, false, null).getQueue();
196192
String x1 = "amq.fanout";

0 commit comments

Comments
 (0)