【发布时间】:2020-07-09 21:11:35
【问题描述】:
是否可以在手动删除队列后自动重新创建队列?
我可以在启动时创建队列
@Bean
public Queue createRandomQueue(@Qualifier("exporterRabbitAdmin") RabbitAdmin exporterRabbitAdmin) {
Queue queue = createQueue("random.queue", exporterRabbitAdmin);
exporterRabbitAdmin.declareQueue(queue);
return queue;
}
但是,如果它是从 rabbitmq 中手动删除的,我希望能够自动创建一个具有相同名称的队列。
今天如果我删除它,我会继续抛出异常
org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[random.queue]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:710) [spring-rabbit-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.passiveDeclarations(BlockingQueueConsumer.java:594) [spring-rabbit-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at ....
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'export-hub-activity.retry.queue' in vhost 'default', class-id=50, method-id=10)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-5.4.3.jar:5.4.3]
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-5.4.3.jar:5.4.3]
【问题讨论】: