Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,10 @@ private static final class Address {

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;
Expand All @@ -970,6 +974,8 @@ private static final class Address {

private String virtualHost;

private boolean isSecureConnection;

private Address(String input) {
input = input.trim();
input = trimPrefix(input);
Expand All @@ -979,6 +985,10 @@ private Address(String input) {
}

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());
}
Expand Down Expand Up @@ -1015,7 +1025,12 @@ private void parseHostAndPort(String input) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ void customPort() {
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
void determinePortReturnsPortOfFirstAddress() {
this.properties.setAddresses("rabbit1.example.com:1234,rabbit2.example.com:2345");
Expand Down