Skip to main content

[Spring Boot] Spring Boot integrates RabbitMQ

[Spring Boot] Spring Boot integrates RabbitMQ

1. Sending and receiving messages

Spring Boot provides the spring-boot-starter- amqp component, which can be seamlessly integrated with Spring Boot by simply configuring it. The following example demonstrates integrating RabbitMQ to receive and send messages.

Step 01 Configure pom package.

Create a Spring Boot project and add spring-bootstarter-amqp and other related component dependencies in the pom.xml file:

    
2.     <groupId>org.springframework.boot</groupId>

3.     <artifactId>spring-boot-starter-amqp</artifactId>

4. </dependency>



In the above example, the amqp component spring-bootstarter-amqp that comes with Spring Boot is introduced.

Step 02 Modify the configuration file.

Modify the application.properties configuration file and configure the host address, port and account information of rabbitmq.

    
2. spring.rabbitmq.port=5672

3. spring.rabbitmq.username=quest

4. spring.rabbitmq.password=quest

5. spring.rabbitmq.virtualHost=order



In the above example, the address of the RabbitMQ service is mainly configured. RabbitMQ configuration is controlled by spring.rabbitmq.* configuration properties. The virtual-host configuration item specifies the virtual host created by the RabbitMQ service, but this configuration item is not required.