Springboot集成Rabbitmq
1.基于Spring-Rabbit操作Rabbitmq
使用spring-boot-starter-amqp会自动添加spring-rabbit依赖
代码如下:
1 | <dependency> |
2.配置
1.配置application.yml文件
连接rabbitmq
1 | server: |
2.定义RabbitConfig类,配置Exchange、Queue、及绑定交换机。
以配置topics交换机为例
1 |
|
3.SpringBootTest单元测试
代码如下
1 |
|
报错
因为之前已经开启并且持久化了一个相同名字的交换机“exchange_topics_inform”,springboot启动就报了io异常
1 | at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(Ra |
解决办法是登录到rabbitmq中把该交换机删掉就行了。