Commit
User can now add credentials, vhost and protocol prefix (amqp://) to any or all of the addresses, extending the format beyond that accepted bu the rabbitmq client, but making it cloud friendly. Only one of the addresses needs those properties and all are optional. Port also defaults to 5672 in an address.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,13 +70,46 @@ public int getPort() { | |
} | ||
|
||
public void setAddresses(String addresses) { | ||
this.addresses = addresses; | ||
this.addresses = parseAddresses(addresses); | ||
} | ||
|
||
public String getAddresses() { | ||
return (this.addresses == null ? this.host + ":" + this.port : this.addresses); | ||
} | ||
|
||
private String parseAddresses(String addresses) { | ||
StringBuilder result = new StringBuilder(); | ||
for (String address : StringUtils.commaDelimitedListToSet(addresses)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dsyer
Member
|
||
address = address.trim(); | ||
if (address.startsWith("amqp://")) { | ||
address = address.substring("amqp://".length()); | ||
} | ||
if (address.contains("@")) { | ||
String[] split = StringUtils.split(address, "@"); | ||
String creds = split[0]; | ||
address = split[1]; | ||
split = StringUtils.split(creds, ":"); | ||
this.username = split[0]; | ||
if (split.length > 0) { | ||
this.password = split[1]; | ||
} | ||
} | ||
int index = address.indexOf("/"); | ||
if (index >= 0 && index < address.length()) { | ||
this.virtualHost = address.substring(index + 1); | ||
address = address.substring(0, index); | ||
} | ||
if (result.length() > 0) { | ||
result.append(","); | ||
} | ||
if (!address.contains(":")) { | ||
address = address + ":" + this.port; | ||
} | ||
result.append(address); | ||
} | ||
return result.length() > 0 ? result.toString() : null; | ||
} | ||
|
||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
1 comment
on commit aa38d33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guys, I'm afraid we can't easily change StringUtils.commaDelimitedListToSet
since it is even documented to return a TreeSet
; I'm rather considering to deprecate it altogether. Preferably, use StringUtils.commaDelimitedListToStringArray
instead which does preserve the original order...
@dsyer I think this is a problem.
People will typically connect to a cluster in "preferred" order in fact they might use a different order on each server to spread the load.
Since
commaDelimitedListToSet
uses aTreeSet
, the addresses will always be sorted.Also, in the code below, the user might anticipate different creds are allowed per address, which is not the case.