动态创建RabbitMQ
创建交换机:
rabbitAdmin.declareExchange(fanoutExchange);
删除交换机:
rabbitAdmin.deleteExchange(exchangeName);
创建队列:
rabbitAdmin.declareQueue(queue);
删除队列:
rabbitAdmin.deleteQueue(queueName);
绑定队列到对应交换机
// 1.创建绑定关系对象
Binding binding =
BindingBuilder
// 创建队列
.bind(new Queue(queueName, true))
// 创建交换机
.to(new TopicExchange(exchange, true, false))
// 指定路由 Key
.with("order#");
// 2.进行绑定
rabbitAdmin.declareBinding(binding);
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(fanoutExchange));
取消交换机队列绑定:
Binding binding = new Binding(queueName, Binding.DestinationType.QUEUE, exchange, "order#", null);
rabbitAdmin.removeBinding(binding);
创建MQ连接:
发送消息:
private RabbitTemplate rabbitTemplate;
rabbitTemplate.convertAndSend(queueName,message);
停止MQ连接: