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");
}
}
重启项目即可。