关于Rabbitmq 指定交换机
1. 系统启动时候,创建交换机和队列。不绑定交换机的话,创建的队列使用默认交换机
但是注意:延迟消息,需要新建一个交换机来指定。默认的支持延迟
@Configuration
public class RabbitmqConfig {
@Bean
public Exchange delayExchange() {
TopicExchange exchange = new TopicExchange("shop.delay");
exchange.setDelayed(true);
return exchange;
}
// 30分钟后取消订单
@Bean
public Queue cancelOrderDelayQueue() {
return new Queue("shop.delay.cancelOrder");
}
@Bean
public Binding cancelOrderDelayBinding() {
return BindingBuilder.bind(cancelOrderDelayQueue()).to(delayExchange())
.with("shop.delay.cancelOrder").noargs();
}
// 7天后确认收货
@Bean
public Queue confirmOrderDelayQueue() {
return new Queue("shop.delay.confirmOrder");
}
@Bean
public Binding confirmOrderDelayBinding() {
return BindingBuilder.bind(confirmOrderDelayQueue()).to(delayExchange())
.with("shop.delay.confirmOrder").noargs();
}
@Bean
public Queue contractFinishQueue() {
return new Queue("shop.contract.finish");
}
@Bean
public Queue taskFinishQueue() {
return new Queue("shop.task.finish");
}
}