-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Improve error message when accidentally specifying multiple hosts in spring.rabbitmq.host #35628
Comments
The test passed. @Test
void test(){
RabbitProperties properties = new RabbitProperties();
properties.setHost("test.com");
properties.setPort(5672);
PropertiesRabbitConnectionDetails details = new PropertiesRabbitConnectionDetails(properties);
assertThat(details.getAddresses()).element(0).isEqualTo(new RabbitConnectionDetails.Address(properties.getHost(), properties.getPort()));
} |
After looking a bit more it looks like the issue is actually in
the It seems like the called method For example, the result of this method is: The caller seems to be expecting the port to be concatenated to the end of each host |
I've added a test using your values from the properties: @Test
void name() {
RabbitProperties properties = new RabbitProperties();
properties.setHost("my-rmq-host.net");
properties.setUsername("host_username");
properties.setPassword("host_password");
properties.setPort(5672);
PropertiesRabbitConnectionDetails details = new PropertiesRabbitConnectionDetails(properties);
assertThat(details.getAddresses()).isEqualTo(List.of(new Address("my-rmq-host.net", 5672)));
assertThat(details.getVirtualHost()).isNull();
assertThat(details.getUsername()).isEqualTo("host_username");
assertThat(details.getPassword()).isEqualTo("host_password");
} This passes. It also works when putting those properties in an Please provide the YAML which doesn't work, or a minimal sample which we can use to reproduce the problem. Thanks! |
Thanks, If you change |
I think the To answer your question:
No, we didn't deprecate anything. They're still supported. It's only your usage of them worked by accident in the past. You should change your config to use addresses if having more than 1 host. |
Makes sense, however from looking around it seems like the previous behavior did allow for this. I'm wondering if it would still be worthwhile to either provide a better error message here or maybe even revert to the old behavior. Since both these fields essentially seem do the same thing and even share an implementation maybe in the future it would be worth deprecating one over the other. |
Yeah, that should be possible. |
Thanks for the support - this is clear to me now. |
We're going to add a check for a |
Hello, is this issue available for work? |
Yes, feel free to work on it. I'll assign the issue to you, please also make sure you have read our contributing document and here are some tips how to get started. If you encounter any problems, feel free to reach out. Have fun! |
As discussed on issue spring-projects#35628, at some point the host property accepted multiple comma-separated hosts. However, this was not intended, and for better clarification, it was decided to implement a clearer error message for this situation.
Hello, I believe I have a solution ready. However, before opening a PR, I would like to confirm some points, as this is my first contribution. I did as suggested and implemented a check for commas on I also implemented a test case to validate the solution: Thanks. |
Hey @rafaelrc7, this looks good, thank you very much!
The changes look good, please create a PR. |
Superseded by #35684. |
When using YAML configuration with the Spring Boot AMQP starter in version 3.0.x it was possible to omit the
addresses
configuration property and instead usehost
andport
.For example:
After upgrading to Spring Boot 3.1.0 this configuration option no longer works. The service fails to start with a
java.lang.ArrayIndexOutOfBoundsException
.The root cause of this looks to be inside the
RabbitConnectionFactoryBeanConfigurer
, specificallyAddress address = this.connectionDetails.getFirstAddress();
In the case I described above the local
RabbitConnectionDetails
class already has a host, port, username and password configured. The values in these fields match the YAML configuration I described above. It looks like thepublic void configure(RabbitConnectionFactoryBean factory)
is not attempting to use these values but instead requiring them to be set on anAddress
. With noaddress
defined in my application yaml this change results in anArrayIndexOutOfBoundsException
.Is this change intended? Is the
rabbitmq.host
property now deprecated and replaced byaddresses
? If so is theport
property also deprecated?The text was updated successfully, but these errors were encountered: