1.我在上一篇博文已经介绍过linux服务器rabbitmq的安装和配置了https://blog.csdn.net/qq_37759106/article/details/81512410现在来介绍一下spring boot如何使用配置
2.maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
3.yml文件配置
这个地方很容易出问题,我会在后面讲到
4.发送者
/**
* 配置队列
* @return
*/
@Bean
public Queue wiselyQueue(){
return new Queue("queue");
}
@Override
public void run(String... args) throws Exception {
rabbitTemplate.convertAndSend("queue","Hello RabbitMQ!");
}
5.接收者
@Component
public class Receiver {
@RabbitListener(queues = "queue")
public void ReceiveMesaage(String message){
System.out.println("接受到"+message);
}
}
6.启动spring boot完成后
7.常见问题
原因:因为之前安装环境时不知道为什么默认的用户名/密码:guest/guest ,然后通过下面新建的用户yida,只有登陆的权限,但是没有管理队列的权限
8.解决方案:点击你新添加用户名,设置管理队列的权限即可