Skip to content

Improve error message when accidentally specifying multiple hosts in spring.rabbitmq.host #35628

@francis-a

Description

@francis-a

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 use host and port.

For example:

spring:
  rabbitmq:
    host: "my-rmq-host.net"
    username: "host_username"
    password: "host_password"
    port: 5672

After upgrading to Spring Boot 3.1.0 this configuration option no longer works. The service fails to start with a java.lang.ArrayIndexOutOfBoundsException.

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at org.springframework.boot.autoconfigure.amqp.PropertiesRabbitConnectionDetails.getAddresses(PropertiesRabbitConnectionDetails.java:57) ~[spring-boot-autoconfigure-3.1.0.jar:3.1.0]
	at org.springframework.boot.autoconfigure.amqp.RabbitConnectionDetails.getFirstAddress(RabbitConnectionDetails.java:71) ~[spring-boot-autoconfigure-3.1.0.jar:3.1.0]
	at org.springframework.boot.autoconfigure.amqp.RabbitConnectionFactoryBeanConfigurer.configure(RabbitConnectionFactoryBeanConfigurer.java:98) ~[spring-boot-autoconfigure-3.1.0.jar:3.1.0]
	at org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$RabbitConnectionFactoryCreator.rabbitConnectionFactory(RabbitAutoConfiguration.java:126) ~[spring-boot-autoconfigure-3.1.0.jar:3.1.0]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) ~[spring-beans-6.0.9.jar:6.0.9]
	... 62 common frames omitted

The root cause of this looks to be inside the RabbitConnectionFactoryBeanConfigurer, specifically Address 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 the public void configure(RabbitConnectionFactoryBean factory) is not attempting to use these values but instead requiring them to be set on an Address. With no address defined in my application yaml this change results in an ArrayIndexOutOfBoundsException.

Is this change intended? Is the rabbitmq.host property now deprecated and replaced by addresses? If so is the port property also deprecated?

Metadata

Metadata

Assignees

Labels

status: supersededAn issue that has been superseded by another

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions