rabbitmqTemplate判断队列是否存在
解决方法:
1.在springboot的启动类中加配置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;
Properties queueProperties = amqpAdmin.getQueueProperties(queueName);
如果queueProperties 不为null的话说明队列存在