Spring 动态管理RabbitMQ队列

南楼画角 提交于 2019-11-30 22:02:33

学习RabbitMQ时创建队列我使用了一下2种方式

1.代码中静态创建队列。

@Configuration
public class RabbitConfig {

    @Bean
    public Queue helloQueue() {
        return new Queue("hello");
    }
}

2.通过http:*****:15672 的页面控制上对队列的

现在想管理队列,所以动态创建删除队列。

1.配置依赖

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

2.配置application.properties

spring.rabbitmq.host=192.168.202.128
spring.rabbitmq.port=5672
spring.rabbitmq.username=root
spring.rabbitmq.password=123

3.注入ConnectionFactory

@Resource(name="rabbitConnectionFactory")
    private ConnectionFactory connectionFactory;

4.创建队列

connectionFactory.createConnection().createChannel(false).queueDeclare("queue_"+UUID.randomUUID().toString().replaceAll("-",""), true, false, false, null);

5.删除队列

connectionFactory.createConnection().createChannel(false).queueDelete("queue_63bc1433755a4ffb9f08a282057f5f1c");

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!