【异常】SptingBoot+RabbitMQ整合出现的异常

本文介绍了在SpringBoot应用中整合RabbitMQ时遇到的异常情况及解决方法。异常包括启动时权限问题和队列未找到的问题。解决办法包括修改RabbitMQ用户权限和在项目中创建相应配置类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,

启动主类,报如下异常:

c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured (Exception message: Socket closed)

在application.properties中,关于rabbitMQ的配置如下:

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=springbootba
spring.rabbitmq.password=123456

启动rabbit server,访问 http://localhost:15672/ ,使用默认账户 guest / guest 可以正常访问。
在这里插入图片描述
在配置文件中的 springbootba 用户,是我们自己新建的一个用户。
在这里插入图片描述
看到上图,基本上可以猜到该异常的解决办法了。

解决办法:

1),点击上图中的我们创建的账户“springbootba”。
2),在这里插入图片描述
此时,“springbootba”用户的权限已改变。
在这里插入图片描述
3),主类正常启动

2019-05-06 18:19:16.196  INFO 5976 --- [askExecutor-130] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@6dda63e1: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
2019-05-06 18:19:16.198  INFO 5976 --- [askExecutor-131] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [localhost:5672]
2019-05-06 18:19:16.214  INFO 5976 --- [askExecutor-131] o.s.a.r.c.CachingConnectionFactory       : Created new connection: rabbitConnectionFactory#47903ab3:260/SimpleConnection@11cb4bf9 [delegate=amqp://springbootba@127.0.0.1:5672/, localPort= 57298]

2,

启动主类,报如下异常:

2019-05-06 18:25:23.493  WARN 5440 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue: helloZyh
2019-05-06 18:25:23.496  WARN 5440 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer   : Queue declaration failed; retries left=3

这个异常显而易见,是由于找不到 名为“helloZyh”的队列引起的。

解决办法

1),第一种解决办法,简单粗暴,直接在控制台创建我们需要的队列即可。
在这里插入图片描述

2),现在我们说一下第二种解决办法。
在项目中,新建一个配置类 RabbitConfig ,如下:

@Configuration
public class RabbitConfig {

    @Bean
    public Queue helloZyhQueue(){
        return new Queue("helloZyh");
    }
}

重启项目即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值