RabbitMQ 的使用

RabbitMQ 的使用

1、首先打卡 pom.xml 文件。

2、在 dependencies 节点下加入

<!-- rabbitMQ -->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-amqp</artifactId>
 </dependency>
<!-- end -->

然后刷新 maven

3、配置 RabbitMQ,在 yml 文件的 spring 节点中添加

rabbitmq:
    host: ip
    port: 5672
    username: zolmk
    password: zolmk

4、在 SpringBootApplication 处开启消息队列,即添加 @EnableRabbit 注解

@EnableRabbit
@SpringBootApplication
public class BmsApplication
{
    public static void main (String[] args)
    {
        SpringApplication.run(BmsApplication.class, args);
    }

}

5、直接自动注入 RabbitTemplete 发送接收消息,Service 中可以使用 @RabbitListener 注解监听消息

posted @ 2020-12-02 15:33  zolmk  阅读(76)  评论(0编辑  收藏  举报