I'm following this guide to learn how to use spring-rabbit
with RabbitMQ. However in this guide, the RabbitMQ configuration is as default(localhost server and with credential as guest/guest). What should I do if I want to connect to an remote RabbitMQ with ip address and credential? I don't know where to set these information in my application.
Asked
Active
Viewed 6.6k times
42

Gary Russell
- 166,535
- 14
- 146
- 179

kenshinji
- 2,021
- 4
- 25
- 39
1 Answers
86
The application for that guide is a Spring Boot Application.
Add a file application.properties
to src/main/resources
.
You can then configure rabbitmq properties according to the Spring Boot Documentation - scroll down to the rabbitmq properties...
...
spring.rabbitmq.host=localhost # RabbitMQ host.
...
spring.rabbitmq.password= # Login to authenticate against the broker.
spring.rabbitmq.port=5672 # RabbitMQ port.
...
spring.rabbitmq.username= # Login user to authenticate to the broker.
...
To connect to a cluster, use
spring.rabbitmq.addresses= # Comma-separated list of addresses to which the client should connect.
e.g. server1:5672,server2:5672
.
If you don't want to use boot auto configuration, declare a CachingConnectionFactory
@Bean
yourself and configure it as desired.

Gary Russell
- 166,535
- 14
- 146
- 179
-
1It's weird, I added these properties into `application.properties` as you suggested. However, these properties seems haven't been loaded into the running application. Anything I missed? – kenshinji Feb 27 '17 at 07:03
-
I just downloaded the guide, added `application.properties` to `src/main/resources` for the `complete` version and pointed it to a remote rabbitmq instance and it worked just fine - I see the queue created on the rabbit instance and the output messages. How are you running the guide? – Gary Russell Feb 27 '17 at 14:22
-
1My bad, sorry, your solution works like a charm. It didn't work here because I added `@Bean MessageListenerAdapter listenerAdapter(Receiver receiver) { return new MessageListenerAdapter(receiver, "receiveMessage");}` in my configuration class. – kenshinji Feb 28 '17 at 02:06
-
1How do you achieve this programatically? – Airwavezx Aug 19 '18 at 08:13
-
It's not clear what you mean; see [the documentation](https://docs.spring.io/spring-amqp/reference/html/) and [samples](https://github.com/spring-projects/spring-amqp-samples). It's better to ask a completely new question rather than asking a new question in a comment on an old one. – Gary Russell Aug 19 '18 at 12:05
-
@GaryRussell with spring boot I am using application.yml and configured all ssl properties from Appendix A except ssl algorithm. In this case my application always tries PLAIN authentication. I know that defining EXTERNAL sasl config can resolve it, I am looking for any configuration I need to make to do that without defining any beans. Can I add any property in application yml and achieve it? – dev2d Dec 12 '18 at 21:51
-
As I stated above; you must not ask new questions in a comment on a very old answer; ask a new question showing your current configuration and exactly what you are trying to achieve. – Gary Russell Dec 12 '18 at 22:22
-
@GaryRussell Thanks for quick response - I have asked a new question here request your help : https://stackoverflow.com/questions/53752686/spring-rmq-listener-always-use-plain-auth-even-after-configuring-ssl-properties – dev2d Dec 12 '18 at 23:00
-
Hi! Do you know how can I connect a kubernetes rabbitmq cluster using your the addresses properties? Or any approach. Currently I've tried bellow approach but no success. The rabbitmq-service is of loadbalancer type. spring.rabbitmq.addresses=http://rabbitmq-0.rabbitmq-service:5672,http://rabbitmq-1.rabbitmq-service:5672 – Vanderson Assis Apr 21 '20 at 21:54
-
Don't ask questions in comments on 3 year old answers; I am not a k8s expert; people from the Kubernetes community won't see it; ask a new question instead, tagged with the relevant technologies. Why do you have `http:` in there? – Gary Russell Apr 21 '20 at 22:04