我有一个部署到heroku的服务。我的服务使用cloudamqp作为云消息服务。当我在本地环境连接上运行的服务成功并且我从未发现此错误时。
但是当我将我的服务部署到heroku时,我收到了这个错误。
2017-10-30T06:03:05.231416+00:00 app[web.1]: 2017-10-30 06:03:05.231 INFO 4 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2017-10-30T06:03:05.256787+00:00 app[web.1]: 2017-10-30 06:03:05.256 INFO 4 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The response status is 200
2017-10-30T06:03:07.002922+00:00 app[web.1]: 2017-10-30 06:03:07.002 WARN 4 --- [nfoReplicator-0] o.s.b.a.health.RabbitHealthIndicator : Health check failed
2017-10-30T06:03:07.002970+00:00 app[web.1]:
2017-10-30T06:03:07.002971+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2017-10-30T06:03:07.002972+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62)
2017-10-30T06:03:07.002972+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368)
2017-10-30T06:03:07.002973+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:573)
2017-10-30T06:03:07.002974+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430)
2017-10-30T06:03:07.002974+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411)
2017-10-30T06:03:07.002975+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387)
2017-10-30T06:03:07.002976+00:00 app[web.1]: at org.springframework.boot.actuate.health.RabbitHealthIndicator.getVersion(RabbitHealthIndicator.java:49)
2017-10-30T06:03:07.002976+00:00 app[web.1]: at org.springframework.boot.actuate.health.RabbitHealthIndicator.doHealthCheck(RabbitHealthIndicator.java:45)
2017-10-30T06:03:07.002977+00:00 app[web.1]: at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:43)
2017-10-30T06:03:07.002977+00:00 app[web.1]: at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68)
2017-10-30T06:03:07.002978+00:00 app[web.1]: at org.springframework.cloud.netflix.eureka.EurekaHealthCheckHandler.getHealthStatus(EurekaHealthCheckHandler.java:103)
2017-10-30T06:03:07.002978+00:00 app[web.1]: at org.springframework.cloud.netflix.eureka.EurekaHealthCheckHandler.getStatus(EurekaHealthCheckHandler.java:99)
2017-10-30T06:03:07.002978+00:00 app[web.1]: at com.netflix.discovery.DiscoveryClient.refreshInstanceInfo(DiscoveryClient.java:1362)
2017-10-30T06:03:07.002979+00:00 app[web.1]: at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:100)
2017-10-30T06:03:07.002980+00:00 app[web.1]: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
2017-10-30T06:03:07.002980+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2017-10-30T06:03:07.002981+00:00 app[web.1]: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
2017-10-30T06:03:07.002981+00:00 app[web.1]: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
2017-10-30T06:03:07.002982+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2017-10-30T06:03:07.002983+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2017-10-30T06:03:07.002983+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748)
2017-10-30T06:03:07.002984+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)
2017-10-30T06:03:07.002985+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method)
2017-10-30T06:03:07.002985+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
2017-10-30T06:03:07.002986+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
2017-10-30T06:03:07.002987+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
2017-10-30T06:03:07.002987+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
2017-10-30T06:03:07.002988+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589)
2017-10-30T06:03:07.002989+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:50)
2017-10-30T06:03:07.002989+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907)
2017-10-30T06:03:07.002990+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
2017-10-30T06:03:07.002990+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799)
2017-10-30T06:03:07.002991+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:352)
2017-10-30T06:03:07.002992+00:00 app[web.1]: ... 19 common frames omitted
2017-10-30T06:03:07.002993+00:00 app[web.1]:
当我看到我的rabbitmq管理页面时,我的服务成功连接到我的cloudamqp rabbitmq服务器。像这样显示
这是我的服务中的application.yml ..
spring:
application:
name: filehandler
jackson:
serialization.write_dates_as_timestamps: false
jpa:
open-in-view: false
hibernate:
ddl-auto: update
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
messages:
basename: i18n/messages
mvc:
favicon:
enabled: false
thymeleaf:
mode: XHTML
cloud:
stream:
bindings:
fileOutput:
destination: file
binder: rabbitmqserver
contentType: application/x-java-serialized-object
indexInput:
destination: index
binder: rabbitmqserver
contentType: application/x-java-serialized-object
binders:
rabbitmqserver:
type: rabbit
environment:
spring:
rabbitmq:
addresses: elephant.rmq.cloudamqp.com
username: username
password: password
virtual-host: virtualhost
有人可以帮我解决这个问题。
答案 0 :(得分:1)
修正了它,
忘记禁用RabbitAutoConfiguration,导致我的服务连接localhost:5672 messagebroker服务器。
通过添加
来修复它@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})
根据此页面https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/blob/master/spring-cloud-stream-binder-rabbit-docs/src/main/asciidoc/overview.adoc,在Spring云流应用程序上使用多个绑定器时禁用RabbitAutoConfiguration非常重要。
答案 1 :(得分:0)
禁用rabbitmq管理运行状况检查,我不知道它正在做什么,但它会导致您的问题:
management.health.rabbit.enabled=false
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html