解决rabbitmq DeclarationException: Failed to declare queue异常

时间:2025-02-18 07:57:28
异常描述

创建队列进行消息发送的时候报错

$DeclarationException: Failed to declare queue(s):[]
    at (:721) ~[spring-rabbit-1.7.:na]
    at (:598) ~[spring-rabbit-1.7.:na]
    at $(:1504) [spring-rabbit-1.7.:na]
    at (:748) [na:1.8.0_131]
Caused by: : null
    at (:105) ~[amqp-client-4.0.:4.0.3]
    at (:101) ~[amqp-client-4.0.:4.0.3]
    at (:123) ~[amqp-client-4.0.:4.0.3]
    at (:992) ~[amqp-client-4.0.:4.0.3]
    at (:50) ~[amqp-client-4.0.:4.0.3]
    at .invoke0(Native Method) ~[na:1.8.0_131]
    at (:62) ~[na:1.8.0_131]
    at (:43) ~[na:1.8.0_131]
    at (:498) ~[na:1.8.0_131]
    at $(:1027) ~[spring-rabbit-1.7.:na]
    at .$(Unknown Source) ~[na:na]
    at (:700) ~[spring-rabbit-1.7.:na]
    ... 3 common frames omitted
Caused by: : channel error; protocol method: #method<>(reply-code=404, reply-text=NOT_FOUND - no queue '' in vhost '/', class-id=50, method-id=10)
    at (:66) ~[amqp-client-4.0.:4.0.3]
    at (:32) ~[amqp-client-4.0.:4.0.3]
    at $(:366) ~[amqp-client-4.0.:4.0.3]
    at (:229) ~[amqp-client-4.0.:4.0.3]
    at (:117) ~[amqp-client-4.0.:4.0.3]
    ... 12 common frames omitted
解决思路

队列找不到,排查发现没有在@Configuration文件中配置该队列,

在配置类中添加上相关队列即可

@Configuration
public class MQConfig {

    public static final String MIAOSHA_QUEUE = "";

    @Bean
    public Queue miaoShaQueue(){
        return new Queue(MIAOSHA_QUEUE,true);
    }
}