I can connect to a RabbitMQ over amqp+ssl by setting these properties:
spring.rabbitmq.host: 10.0.0.123
spring.rabbitmq.password: password
spring.rabbitmq.port: 5671
spring.rabbitmq.ssl.enabled: true
spring.rabbitmq.username: user
spring.rabbitmq.virtualHost: virtualhost
I would expect that this would work as well
spring.rabbitmq.addresses: amqps://user:[email protected]/virtualhost
But https://github.com/spring-projects/spring-boot/blob/v1.3.6.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java#L118 doesn't handle the amqps scheme. See https://www.rabbitmq.com/uri-spec.html for the spec on the amqps URI scheme.
This is slightly complicated by the fact that amqp and amqps URIs have different default ports (5672 and 5671 respectively).
I think fixing #6424 is a prereq for adding support for amqps addresses and I don't think #6424 should be tackled in 1.3.x.
I had a similar issue while deploying a Spring AMQP app on PCF. With the current RabbitMQ Java client, the default SSL Protocol is TLSv1 and that errors out when TLS 1 is disabled from the PCF-Rabbit tile. I had to add the following properties -
spring.rabbitmq.host=${vcap.services.swagataRMQService1.credentials.hostname}
spring.rabbitmq.port=5671
spring.rabbitmq.virtual-host=${vcap.services.swagataRMQService1.credentials.vhost}
spring.rabbitmq.username=${vcap.services.swagataRMQService1.credentials.username}
spring.rabbitmq.password=${vcap.services.swagataRMQService1.credentials.password}
spring.rabbitmq.ssl.enabled=${vcap.services.swagataRMQService1.credentials.ssl}
spring.rabbitmq.ssl.algorithm=TLSv1.2
I was hoping that only adding the following would resolve my issue -
spring.rabbitmq.addresses=${vcap.services.swagataRMQService1.credentials.uri}
Please note that the uri property from VCAP_SERVICES is as follows -
"uri": "amqps://2249d8f6-52c2-4dc7-8f37-67717d75cf79:[email protected]/ff8ca300-59b4-467b-9c39-9a2df7dceeeb",
The code here - https://github.com/spring-projects/spring-boot/blob/v1.3.6.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java#L122 needs to check for amqps also and the port should be set to 5671 for amqps
@treevez the original reporter mentioned that setting individual properties work so this is issue is about convenience of putting the full URL. If that doesn't work for you, please ask on StackOverflow or join us on Gitter.
That said, you have the full history of the issue right here and I am afraid we haven't had a chance to make progress on this enhancement.
You can override boot's auto configured connection factory.
@SpringBootApplication
public class So46937522Application {
public static void main(String[] args) {
SpringApplication.run(So46937522Application.class, args);
}
@Bean
public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config)
throws Exception {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.getRabbitConnectionFactory().setUri("amqps://guest:[email protected]:5671/virtualhost");
return connectionFactory;
}
@RabbitListener(queues = "si.test.queue")
public void listen(Message in) {
System.out.println(in);
}
}
Closing in favor of PR #18808
Most helpful comment
You can override boot's auto configured connection factory.