Commit 0c52817c authored by Dave Syer's avatar Dave Syer

Ensure order is preserved in Rabbit addresses

Using StringUtils.commaDelimitedListToSet() does not preserve order (why?),
so we have to use commaDelimitedListToStringArray().

Fixes gh-1262
parent 8853c7c3
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
package org.springframework.boot.autoconfigure.amqp; package org.springframework.boot.autoconfigure.amqp;
import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -78,8 +81,8 @@ public class RabbitProperties { ...@@ -78,8 +81,8 @@ public class RabbitProperties {
} }
private String parseAddresses(String addresses) { private String parseAddresses(String addresses) {
StringBuilder result = new StringBuilder(); Set<String> result = new LinkedHashSet<String>();
for (String address : StringUtils.commaDelimitedListToSet(addresses)) { for (String address : StringUtils.commaDelimitedListToStringArray(addresses)) {
address = address.trim(); address = address.trim();
if (address.startsWith("amqp://")) { if (address.startsWith("amqp://")) {
address = address.substring("amqp://".length()); address = address.substring("amqp://".length());
...@@ -99,15 +102,12 @@ public class RabbitProperties { ...@@ -99,15 +102,12 @@ public class RabbitProperties {
this.virtualHost = address.substring(index + 1); this.virtualHost = address.substring(index + 1);
address = address.substring(0, index); address = address.substring(0, index);
} }
if (result.length() > 0) {
result.append(",");
}
if (!address.contains(":")) { if (!address.contains(":")) {
address = address + ":" + this.port; address = address + ":" + this.port;
} }
result.append(address); result.add(address);
} }
return result.length() > 0 ? result.toString() : null; return result.isEmpty() ? null : StringUtils.collectionToCommaDelimitedString(result);
} }
public void setPort(int port) { public void setPort(int port) {
......
...@@ -59,6 +59,13 @@ public class RabbitPropertiesTests { ...@@ -59,6 +59,13 @@ public class RabbitPropertiesTests {
assertEquals("host", this.properties.getVirtualHost()); assertEquals("host", this.properties.getVirtualHost());
} }
@Test
public void addressesDoubleValuedPreservesOrder() {
this.properties.setAddresses("myhost:9999,ahost:1111/host");
assertNull(this.properties.getHost());
assertEquals("myhost:9999,ahost:1111", properties.getAddresses());
}
@Test @Test
public void addressesSingleValuedWithCredentials() { public void addressesSingleValuedWithCredentials() {
this.properties.setAddresses("amqp://root:password@otherhost:1111/host"); this.properties.setAddresses("amqp://root:password@otherhost:1111/host");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment