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.
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.
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!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With