Skip to content

Commit ee3b351

Browse files
committed
Add arguments(Map) method to exchange and queue specification
Fixes #153
1 parent 6ddce25 commit ee3b351

File tree

10 files changed

+58
-16
lines changed

10 files changed

+58
-16
lines changed

src/main/java/com/rabbitmq/client/amqp/Management.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ interface QueueSpecification {
296296
*/
297297
QueueSpecification argument(String key, Object value);
298298

299+
/**
300+
* Set the queue arguments.
301+
*
302+
* <p>The argument map will replace any existing arguments.
303+
*
304+
* @param arguments arguments
305+
* @return the queue specification
306+
*/
307+
QueueSpecification arguments(Map<String, Object> arguments);
308+
299309
/**
300310
* Declare the queue.
301311
*
@@ -662,6 +672,16 @@ interface ExchangeSpecification {
662672
*/
663673
ExchangeSpecification argument(String key, Object value);
664674

675+
/**
676+
* Set the exchange arguments.
677+
*
678+
* <p>The argument map will replace any existing arguments.
679+
*
680+
* @param arguments arguments
681+
* @return the exchange specification
682+
*/
683+
ExchangeSpecification arguments(Map<String, Object> arguments);
684+
665685
/** Declare the exchange. */
666686
void declare();
667687
}
@@ -769,7 +789,9 @@ interface BindingSpecification {
769789
BindingSpecification argument(String key, Object value);
770790

771791
/**
772-
* Binding arguments.
792+
* Set the binding arguments.
793+
*
794+
* <p>The argument map will replace any existing arguments.
773795
*
774796
* @param arguments arguments
775797
* @return the binding specification
@@ -826,7 +848,9 @@ interface UnbindSpecification {
826848
UnbindSpecification argument(String key, Object value);
827849

828850
/**
829-
* Binding arguments.
851+
* Set the binding arguments.
852+
*
853+
* <p>The argument map will replace any existing arguments.
830854
*
831855
* @param arguments arguments
832856
* @return the unbind specification

src/main/java/com/rabbitmq/client/amqp/impl/AmqpBindingManagement.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public Management.BindingSpecification argument(String key, Object value) {
101101

102102
@Override
103103
public Management.BindingSpecification arguments(Map<String, Object> arguments) {
104+
Assert.notNull(arguments, "Arguments");
104105
this.state.arguments.clear();
105106
this.state.arguments.putAll(arguments);
106107
return this;
@@ -169,6 +170,7 @@ public Management.UnbindSpecification argument(String key, Object value) {
169170

170171
@Override
171172
public Management.UnbindSpecification arguments(Map<String, Object> arguments) {
173+
Assert.notNull(arguments, "Arguments");
172174
this.state.arguments.clear();
173175
this.state.arguments.putAll(arguments);
174176
return this;

src/main/java/com/rabbitmq/client/amqp/impl/AmqpConsumerBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ public StreamOptions offset(long offset) {
152152

153153
@Override
154154
public StreamOptions offset(Instant timestamp) {
155-
notNull(timestamp, "Timestamp offset cannot be null");
155+
notNull(timestamp, "Timestamp offset");
156156
return this.offsetSpecification(Date.from(timestamp));
157157
}
158158

159159
@Override
160160
public StreamOptions offset(StreamOffsetSpecification specification) {
161-
notNull(specification, "Offset specification cannot be null");
161+
notNull(specification, "Offset specification");
162162
return this.offsetSpecification(specification.name().toLowerCase(Locale.ENGLISH));
163163
}
164164

165165
@Override
166166
public StreamOptions offset(String interval) {
167-
notNull(interval, "Interval offset cannot be null");
167+
notNull(interval, "Interval offset");
168168
if (!Utils.validateMaxAge(interval)) {
169169
throw new IllegalArgumentException(
170170
"Invalid value for interval: "

src/main/java/com/rabbitmq/client/amqp/impl/AmqpExchangeSpecification.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public Management.ExchangeSpecification argument(String key, Object value) {
7373
return this;
7474
}
7575

76+
@Override
77+
public Management.ExchangeSpecification arguments(Map<String, Object> arguments) {
78+
Assert.notNull(arguments, "Arguments");
79+
this.arguments.clear();
80+
this.arguments.putAll(arguments);
81+
return this;
82+
}
83+
7684
@Override
7785
public void declare() {
7886
// TODO check name is specified (server-named entities not allowed)

src/main/java/com/rabbitmq/client/amqp/impl/AmqpQueueSpecification.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ public Management.QueueSpecification argument(String key, Object value) {
183183
return this;
184184
}
185185

186+
@Override
187+
public Management.QueueSpecification arguments(Map<String, Object> arguments) {
188+
Assert.notNull(arguments, "Arguments");
189+
this.arguments.clear();
190+
this.arguments.putAll(arguments);
191+
return this;
192+
}
193+
186194
@Override
187195
public Management.QueueInfo declare() {
188196
Map<String, Object> body = new LinkedHashMap<>();

src/main/java/com/rabbitmq/client/amqp/impl/Assert.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ abstract class Assert {
2121

2222
private Assert() {}
2323

24-
static void notNull(Object object, String message) {
24+
static void notNull(Object object, String label) {
2525
if (object == null) {
26-
throw new IllegalArgumentException(message);
26+
throw new IllegalArgumentException(label + " cannot be null");
2727
}
2828
}
2929
}

src/main/java/com/rabbitmq/client/amqp/impl/DefaultConnectionSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public Affinity<T> reuse(boolean reuse) {
486486

487487
@Override
488488
public Affinity<T> strategy(AffinityStrategy strategy) {
489-
Assert.notNull(strategy, "Affinity strategy cannot be null");
489+
Assert.notNull(strategy, "Affinity strategy");
490490
this.strategy = strategy;
491491
return this;
492492
}

src/test/java/com/rabbitmq/client/amqp/impl/AmqpConnectionAffinityUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ AffinityCacheAssert contains(Management.QueueInfo info) {
316316
}
317317

318318
AffinityCacheAssert doesNotContainInfoFor(String queue) {
319-
Assert.notNull(queue, "Queue argument cannot be null");
319+
Assert.notNull(queue, "Queue argument");
320320
isNotNull();
321321

322322
Management.QueueInfo queueInfo = actual.queueInfo(queue);

src/test/java/com/rabbitmq/client/amqp/impl/Assertions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ QueueInfoAssert is(Management.QueueType type) {
161161
}
162162

163163
QueueInfoAssert hasLeader(String leader) {
164-
Assert.notNull(leader, "Expected leader cannot be null");
164+
Assert.notNull(leader, "Expected leader");
165165
isNotNull();
166166
if (!leader.equals(actual.leader())) {
167167
fail("Queue leader should be '%s' but is '%s'", leader, actual.leader());
@@ -170,7 +170,7 @@ QueueInfoAssert hasLeader(String leader) {
170170
}
171171

172172
QueueInfoAssert doesNotHaveLeader(String leader) {
173-
Assert.notNull(leader, "Leader cannot be null");
173+
Assert.notNull(leader, "Leader");
174174
isNotNull();
175175
if (leader.equals(actual.leader())) {
176176
fail("Queue leader should not be '%s'", leader);
@@ -368,7 +368,7 @@ private ConnectionAssert(AmqpConnection connection) {
368368
}
369369

370370
ConnectionAssert hasNodename(String nodename) {
371-
Assert.notNull(nodename, "Expected nodename cannot be null");
371+
Assert.notNull(nodename, "Expected nodename");
372372
isNotNull();
373373
if (!actual.connectionNodename().equals(nodename)) {
374374
fail(
@@ -379,7 +379,7 @@ ConnectionAssert hasNodename(String nodename) {
379379
}
380380

381381
ConnectionAssert isOnLeader(Management.QueueInfo info) {
382-
Assert.notNull(info, "Queue info cannot be null");
382+
Assert.notNull(info, "Queue info");
383383
String actualLeader = info.leader();
384384
if (!actualLeader.equals(actual.connectionNodename())) {
385385
fail(
@@ -390,7 +390,7 @@ ConnectionAssert isOnLeader(Management.QueueInfo info) {
390390
}
391391

392392
ConnectionAssert isOnFollower(Management.QueueInfo info) {
393-
Assert.notNull(info, "Queue info cannot be null");
393+
Assert.notNull(info, "Queue info");
394394
List<String> followers =
395395
info.members().stream()
396396
.filter(n -> !n.equals(info.leader()))

src/test/java/com/rabbitmq/client/amqp/impl/Cli.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void restartStream(String stream) {
240240

241241
static void pauseNode(String node) {
242242
String containerId = DOCKER_NODES_TO_CONTAINERS.get(node);
243-
Assert.notNull(containerId, "No container for node " + node);
243+
Assert.notNull(containerId, "Container ID for node " + node);
244244
executeCommand("docker pause " + containerId);
245245
}
246246

@@ -291,7 +291,7 @@ static List<String> nodes() {
291291

292292
private static String nodeToDockerContainer(String node) {
293293
String containerId = DOCKER_NODES_TO_CONTAINERS.get(node);
294-
Assert.notNull(containerId, "No container for node " + node);
294+
Assert.notNull(containerId, "Container ID for node " + node);
295295
return containerId;
296296
}
297297

0 commit comments

Comments
 (0)