rabbitmq Attempting to connect to: [localhost:5672] SocketExceptio:Socket Closed

今天使用spring cloud stream for rabbitmq启动项目报错:

2019-05-03 13:22:27.350  INFO [file,,,] 18160 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [localhost:5672]
2019-05-03 13:22:32.382 ERROR [file,,,] 18160 --- [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured

java.net.SocketException: Socket Closed
	at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_191]
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_191]
	at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_191]
	at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_191]
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_191]
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_191]
	at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_191]
	at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-5.4.3.jar:5.4.3]
	at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-5.4.3.jar:5.4.3]
	at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:596) ~[amqp-client-5.4.3.jar:5.4.3]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]
复制代码

以为端口有问题。检查了下Docker的端口映射

PS C:\Users\wangn> docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                                                                                      NAMES
8b2958c71e85        rabbitmq:3.7.14-management   "docker-entrypoint.s…"   About an hour ago   Up About an hour    0.0.0.0:4369->4369/tcp, 0.0.0.0:5671-5672->5671-5672/tcp, 0.0.0.0:15671-15672->15671-15672/tcp, 0.0.0.0:25672->25672/tcp   myrabbit
复制代码

没问题。‘

去谷歌了一遍也没有解决。

直到我将application.properties文件中的

spring.rabbitmq.host=localhost
复制代码

换成

spring.rabbitmq.host=10.0.75.2
复制代码

启动就不报错了。

其中10.0.75.2是docker容器的IP地址

你可能感兴趣的:(rabbitmq Attempting to connect to: [localhost:5672] SocketExceptio:Socket Closed)