Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The error message is unhelpful when spring.rabbitmq.host is configured with a comma-separated value #35684

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 @@ -27,6 +27,7 @@
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.ConfirmType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
Expand All @@ -43,6 +44,7 @@
* @author Artsiom Yudovin
* @author Franjo Zilic
* @author Eddú Meléndez
* @author Rafael Carvalho
* @since 1.0.0
*/
@ConfigurationProperties(prefix = "spring.rabbitmq")
Expand Down Expand Up @@ -203,6 +205,10 @@ public String getAddresses() {
*/
public String determineAddresses() {
if (CollectionUtils.isEmpty(this.parsedAddresses)) {
if (this.host.contains(",")) {
throw new InvalidConfigurationPropertyValueException("spring.rabbitmq.host", this.host,
"Invalid character ','. Value must be a single host. For multiple hosts, use property 'spring.rabbitmq.addresses' instead.");
}
return this.host + ":" + determinePort();
}
List<String> addressStrings = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* Tests for {@link RabbitProperties}.
*
* @author Dave Syer
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Rafael Carvalho
*/
class RabbitPropertiesTests {

Expand Down Expand Up @@ -338,4 +341,13 @@ void determineUsernameWithoutPassword() {
assertThat(this.properties.determinePassword()).isEqualTo("guest");
}

@Test
void hostPropertyMustBeSingleHost() {
this.properties.setHost("my-rmq-host.net,my-rmq-host-2.net");
assertThat(this.properties.getHost()).isEqualTo("my-rmq-host.net,my-rmq-host-2.net");
assertThatThrownBy(this.properties::determineAddresses)
.isInstanceOf(InvalidConfigurationPropertyValueException.class)
.hasMessageContaining("spring.rabbitmq.host");
}

}