需求
本地联调的时候,不想把本服务注册到开发环境的nacos中,但是又想用到开发环境的其他服务,又不想影响到开发环境的使用(因为服务注册上去,默认就自动负载均衡)。
解决方案
利用配置的方式指定具体的ip
spring:
cloud:
loadbalancer:
retry:
enabled: false
openfeign:
okhttp:
enabled: true
client:
config:
uaa-service:
url: http://172.18.41.51:17001
xxl-job-service:
url: http://172.18.41.51:17002
oss-service:
url: http://172.18.41.51:17003
sequence-service:
url: http://172.18.41.51:17004
security-service:
url: http://172.18.41.51:17005
system-service:
url: http://172.18.41.51:17006
data-cache-service:
url: http://172.18.41.51:17007
runtime-service:
url: http://localhost:7003
api-service:
url: http://172.18.41.50:17001
gateway-mq-service:
url: http://172.18.41.50:17002
xxljob-executor-service:
url: http://172.18.41.50:17003
gateway-service:
url: http://172.18.41.50:17004
console-service:
url: http://172.18.41.50:17005
根据上面的配置,除了runtime-service是跳转到本地,其他的都指定到开发环境的机器,这样子就可以实现了。但是需要注意的是 FeginClient的注解 @FeignClient url 和path必须不能配置,否则会失效。