Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure RabbitMQ connection with spring-rabbit?

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.

like image 875
kenshinji Avatar asked Feb 13 '17 09:02

kenshinji


People also ask

How does RabbitMQ connect to spring boot?

In another tutorial we have explained the various exchange types and their implementation using Spring Boot. Define the pom. xml as follows- Add the spring-boot-starter-amqp dependency. Define the RabbitMQSender class which sends the message to the RabbitMQ using AmqpTemplate.

How do I use RabbitMQ in spring?

The main() method starts that process by creating a Spring application context. This starts the message listener container, which starts listening for messages. There is a Runner bean, which is then automatically run. It retrieves the RabbitTemplate from the application context and sends a Hello from RabbitMQ!

How do I connect to RabbitMQ server?

In order for a client to interact with RabbitMQ it must first open a connection. This process involves a number of steps: Application configures the client library it uses to use a certain connection endpoint (e.g. hostname and port) The library resolves the hostname to one or more IP addresses.


1 Answers

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.

like image 66
Gary Russell Avatar answered Sep 21 '22 07:09

Gary Russell