远程RabbitMQ无法连接
使用SpringCloud Stream连接RabbitMQ爆org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect异常
观察控制台发现连接的是本地,但是我配置文件中配置的MQ是远程的IP
2021-01-18 11:12:17.265 INFO 14580 — [3)-192.168.1.36] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
并且在此之前使用SpringClod Bus配置的RabbitMQ无异常
解决增加spring.rabbitmq的配置,如果只配置spring.cloud.stream.binders.defaultRabbit.environment只能连接本地localhost即使配置了也没用
完整配置
server:
port: 8801
spring:
application:
name: cloud-stream-provider
cloud:
stream:
binders:
defaultRabbit:
type: rabbit
environment:
spring:
rabbitmq:
# 配置在这里不生效
# host: [IP地址]
# port: 5672
username: user
password: password
bindings:
output:
destination: studyExchange
content-type: application/json
binder: defaultRabbit
rabbitmq:
host: [IP地址]
port: 5672
username: user
password: password
eureka:
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/