spring: rabbitmq:
host: 127.0.0.1
port: 5672
username: admin
password: 123456
virtual-host: /dev
connection-timeout: 5000
template:
retry:
enabled: true
initial-interval: 1000
max-attempts: 3
@Configuration public class DelayQueueConfig {
// 订单超时交换机
@Bean
public DirectExchange orderTimeoutExchange() {
return new DirectExchange("order.timeout.exchange");
}
// 延迟队列,设置5分钟TTL
@Bean
public Queue orderDelayQueue() {
Map<String, Object> args = new HashMap<>();
args.put("x-dead-letter-exchange", "order.timeout.exchange");
args.put("x-dead-letter-routing-key", "order.timeout");
args.put("x-message-ttl", 300000); // 5分钟
return new Queue("order.delay.queue", true, false, false, args);
}
// 实际处理超时订单的队列
@Bean
public Queue orderTimeoutQueue() {
return new Queue("order.timeout.queue", true);
}
@Bean
public Binding timeoutBinding() {
return BindingBuilder.bind(orderTimeoutQueue())
.to(orderTimeoutExchange())
.with("order.timeout");
}
}

你可能想看:
Java优学网SpringBoot整合Kafka教程:快速实现高效消息队列,让开发更轻松
Java优学网SpringBoot整合Redis教程:轻松实现商品信息缓存,提升应用性能
Java优学网List类型Redis短文:LPUSH、RPUSH实现高效队列,轻松解决订单处理难题
Java优学网SpringBoot自动配置讲解:告别配置烦恼,轻松掌握自动化开发技巧
MyBatis查Java优学网类型处理器:轻松实现Java与数据库数据自动转换,告别繁琐手动处理
Java优学网SpringBoot整合Redis讲解:从入门到实战,轻松提升应用性能