SpringCloud zuul的负载均衡策略实现

application.yml

如果是多台服务器

spring:
  application:
    name: api-gateway

server:
  port: 8007
zuul:
  routes:
   user-service:
      path: /user-service/**
      serviceId: user-service2
ribbon:
  eureka:
    enabled: true
user-service2:
  ribbon:
    listOfServers: http://localhost:8003/,http://localhost:8004/

eureka:
  client:
      serviceUrl:
        defaultZone: http://localhost:8002/eureka/

在Spring Cloud Zuul中使用Ribbon 作为负载均衡器,

如果是单台机器,不使用负载均衡,配置就简单了:

spring:
  application:
    name: api-gateway

server:
  port: 8007
zuul:
  routes:
    user-service:
      path:  /user-service/**
      url:  http://localhost:8003
eureka:
  client:
      serviceUrl:
        defaultZone: http://localhost:8002/eureka/
posted @ 2019-07-01 19:27  π。  阅读(5111)  评论(0编辑  收藏  举报