Support amqps:// URIs in spring.rabbitmq.addresses
See gh-18808 Co-Authored-By: Bryan Kelly <xyloman@gmail.com>
This commit is contained in:
parent
ed50bf2494
commit
0fedb24c6f
|
@ -937,6 +937,10 @@ public class RabbitProperties {
|
|||
|
||||
private static final int DEFAULT_PORT = 5672;
|
||||
|
||||
private static final String PREFIX_AMQP_SECURE = "amqps://";
|
||||
|
||||
private static final int DEFAULT_PORT_SECURE = 5671;
|
||||
|
||||
private String host;
|
||||
|
||||
private int port;
|
||||
|
@ -947,6 +951,8 @@ public class RabbitProperties {
|
|||
|
||||
private String virtualHost;
|
||||
|
||||
private boolean isSecureConnection;
|
||||
|
||||
private Address(String input) {
|
||||
input = input.trim();
|
||||
input = trimPrefix(input);
|
||||
|
@ -956,6 +962,10 @@ public class RabbitProperties {
|
|||
}
|
||||
|
||||
private String trimPrefix(String input) {
|
||||
if (input.startsWith(PREFIX_AMQP_SECURE)) {
|
||||
this.isSecureConnection = true;
|
||||
return input.substring(PREFIX_AMQP_SECURE.length());
|
||||
}
|
||||
if (input.startsWith(PREFIX_AMQP)) {
|
||||
input = input.substring(PREFIX_AMQP.length());
|
||||
}
|
||||
|
@ -992,7 +1002,12 @@ public class RabbitProperties {
|
|||
int portIndex = input.indexOf(':');
|
||||
if (portIndex == -1) {
|
||||
this.host = input;
|
||||
this.port = DEFAULT_PORT;
|
||||
if (this.isSecureConnection) {
|
||||
this.port = DEFAULT_PORT_SECURE;
|
||||
}
|
||||
else {
|
||||
this.port = DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.host = input.substring(0, portIndex);
|
||||
|
|
|
@ -70,6 +70,13 @@ public class RabbitPropertiesTests {
|
|||
assertThat(this.properties.getPort()).isEqualTo(1234);
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingSecuredConnections() {
|
||||
this.properties.setAddresses("amqps://root:password@otherhost,amqps://root:password2@otherhost2");
|
||||
assertThat(this.properties.determinePort()).isEqualTo(5671);
|
||||
assertThat(this.properties.determineAddresses()).isEqualTo("otherhost:5671,otherhost2:5671");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinePortReturnsPortOfFirstAddress() {
|
||||
this.properties.setAddresses("rabbit1.example.com:1234,rabbit2.example.com:2345");
|
||||
|
|
Loading…
Reference in New Issue