Skip to content

Commit ced72ed

Browse files
committed
GH-2917: Add AbstractConnectionFactory.setAddresses(List<String>)
Fixes: #2917 In Spring Boot `3.4.0` the `org.springframework.boot.autoconfigure.amqp.RabbitProperties#getAddresses()` returns a `List<String>` while it previously returned a `String`. This makes it incompatible with `AbstractConnectionFactory.setAddresses` which accepts a `String`. Previously we could do `cachingConnectionFactory.setAddresses(rabbitProperties.getAddresses());`, but now have to go with a `cachingConnectionFactory.setAddresses(String.join(",", rabbitProperties.getAddresses()))` * Expose `AbstractConnectionFactory.setAddresses(List<String>)` for the mentioned convenience to be able to use `List<String>` as an alternative to comma-separated string
1 parent 0128f7e commit ced72ed

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactory.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,16 @@ public int getPort() {
344344

345345
/**
346346
* Set addresses for clustering. This property overrides the host+port properties if not empty.
347-
* @param addresses list of addresses with form "host[:port],..."
347+
* @param addresses list of addresses in form {@code host[:port]}.
348+
* @since 3.2.1
349+
*/
350+
public void setAddresses(List<String> addresses) {
351+
Assert.notEmpty(addresses, "Addresses must not be empty");
352+
setAddresses(String.join(",", addresses));
353+
}
354+
/**
355+
* Set addresses for clustering. This property overrides the host+port properties if not empty.
356+
* @param addresses list of addresses with form {@code host1[:port1],host2[:port2],...}.
348357
*/
349358
public void setAddresses(String addresses) {
350359
this.lock.lock();

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactoryTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.mockito.Mockito.verify;
3434

3535
import java.util.Collections;
36+
import java.util.List;
3637
import java.util.concurrent.ExecutorService;
3738
import java.util.concurrent.ThreadFactory;
3839
import java.util.concurrent.atomic.AtomicInteger;
@@ -110,7 +111,7 @@ public void onClose(Connection connection) {
110111

111112
verify(mockConnectionFactory, times(1)).newConnection(any(ExecutorService.class), anyString());
112113

113-
connectionFactory.setAddresses("foo:5672,bar:5672");
114+
connectionFactory.setAddresses(List.of("foo:5672", "bar:5672"));
114115
connectionFactory.setAddressShuffleMode(AddressShuffleMode.NONE);
115116
con = connectionFactory.createConnection();
116117
assertThat(called.get()).isEqualTo(1);

0 commit comments

Comments
 (0)