4-3Ribbon 不再Eureka环境下运行 · SpringCloud微服务实战 · 看云

3. 如何不再Eureka环境下运行

导航

本节代码地址


3.1 修改配置

在无Eureka 环境下如何运行Spring Cloud RIbbon 提供的负载均衡?修改一下application.yml配置

ribbon:
  eureka:
    enabled: false #禁用eurake
# 禁用 Eureka 后手动配置服务地址
fw-cloud-ribbon-server: #服务名称
  ribbon:
    listOfServers: localhost:8773,localhost:8774

这里需要将Eureka设置为false,就是不启用从Eureka获取服务实例,但是需要将已经启动的服务端实例的地址设置在调用服务的后面,规则如下

服务名称(spring.application.name):
    ribbon:
        listOfServers: ip:port,ip:port

3.2 重新启动

通过postman 重新请求localhost:8771/user/1
c83b6b14862bdbf152649d7e931ae511_MD5.png

并且控制台会把配置的实例地址输出来

2019-12-22 15:03:55.411  INFO 19300 --- [nio-8772-exec-2] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client fw-cloud-ribbon-server initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=fw-cloud-ribbon-server,current list of Servers=[localhost:8773, localhost:8774],Load balancer stats=Zone stats: {unknown=[Zone:unknown;	Instance count:2;	Active connections count: 0;	Circuit breaker tripped count: 0;	Active connections per server: 0.0;]
},Server stats: [[Server:localhost:8774;	Zone:UNKNOWN;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 08:00:00 CST 1970;	First connection made: Thu Jan 01 08:00:00 CST 1970;	Active Connections:0;	total failure count in last (1000) msecs:0;	average resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]
, [Server:localhost:8773;	Zone:UNKNOWN;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 08:00:00 CST 1970;	First connection made: Thu Jan 01 08:00:00 CST 1970;	Active Connections:0;	total failure count in last (1000) msecs:0;	average resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]
]}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@d0606e7
localhost:8773
localhost:8774