rabbitmqTemplate动态创建临时队列,时间一到就过期删除
解决方法:
1.配置amqpAdmin
@Bean
@ConditionalOnSingleCandidate(ConnectionFactory.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "dynamic", matchIfMissing = true)
@ConditionalOnMissingBean
public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
}
2.创建临时队列作为缓存
@Autowired
AmqpAdmin amqpAdmin;
Map<String, Object> arguments = new HashMap<>();
arguments.put("x-expires",expire);
Queue queue = new Queue(queueName, false, false, false, arguments);
amqpAdmin.declareQueue(queue);
rabbitTemplate.convertAndSend(queueName ,message);