Zuul指定Path+url以及指定可用的服务节点时如何负载均衡
生活随笔
收集整理的這篇文章主要介紹了
Zuul指定Path+url以及指定可用的服务节点时如何负载均衡
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
你這個東西可以是serviceId,也可以是url,那serviceId剛剛我們已經研究過了,就是注冊中心的serviceId,我們試試url,url: https://example.com/users_serviceThe location of the back end can be specified as either a serviceId (for a service from discovery) or a url (for a physical location), as shown in the following example:zuul:routes:users:path: /myusers/**url: https://example.com/users_servicezuul.routes.user-route.path=/user/**
zuul.routes.user-route.url=http://localhost:7900/其實規則真的很簡單,文檔也寫的很詳細,他說你用URL這種不會被放到HystrixCommand里面去執行,他也不會用Ribbon去負載均衡These simple url-routes do not get executed as a HystrixCommand, nor do they load-balance multiple URLs with Ribbon. To achieve those goals, you can specify a serviceId with a static list of servers, as follows:Another method is specifiying a service-route and configuring a Ribbon client for the serviceId (doing so requires disabling Eureka support in Ribbon?—?see above for more information), as shown in the following example:ribbon:eureka:enabled: falsehttps://cloud.spring.io/spring-cloud-netflix/reference/html/#_zuul_http_client禁止掉Ribbon的Eureka使用ribbon:eureka:enabled: falseusers:ribbon:listOfServers: example.com,google.comribbon.eureka.enabled=false
users.ribbon.listOfServers=http://localhost:7900/,http://localhost:7901/我們這邊不能用url了,還是用serviceIdzuul.routes.user-route.service-id=microservice-simple-provider-user
zuul.routes.user-route.path=/user/**
ribbon.eureka.enabled=false
microservice-simple-provider-user.ribbon.listOfServers=http://localhost:7900/,http://localhost:7901/這邊要注意,這里ribbon要請求的微服務的serviceId,我們之前也試過ribbon without eurekahttp://localhost:8040/user/simple/1顯然是可以打印的,看一下是不是多個節點可以打印日志
server.port=8761
#eureka.instance.hostname=eureka1#spring.application.name=microservice-discovery-eureka
#eureka.server.evictionIntervalTimerInMs=60000
eureka.client.serviceUrl.defaultZone=http://admin:1234@localhost:8761/eureka
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false#eureka.server.enableSelfPreservation=truesecurity.basic.enabled=true
security.user.name=admin
security.user.password=1234spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=truelogging.level.com.learn=trace
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%neureka.datacenter=cloud
eureka.environment=product
#debug=true
server.port=7900#server.context-path=/boot02spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=truelogging.level.com.learn=trace
#logging.file=D:/springboot.log
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%n
#spring.resources.static-locations=classpath:/hello,classpath:/learnspring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://59.110.158.145:3306/SpringCloud?useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xmleureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eurekaspring.application.name=microservice-simple-provider-user
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
#eureka.client.healthcheck.enabled=true
spring.redis.host=10.40.8.152
spring.redis.password=1234
spring.redis.port=6379eureka.instance.appname=microservice-simple-provider-user
server.port=7901spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=truelogging.level.com.learn=trace
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%nspring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://59.110.158.145:3306/SpringCloud?useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xmleureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eurekaspring.application.name=microservice-simple-provider-user
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
#eureka.client.healthcheck.enabled=true
spring.redis.host=10.40.8.152
spring.redis.password=1234
spring.redis.port=6379eureka.instance.appname=microservice-simple-provider-user
server.port=8040
spring.application.name=microservice-gateway-zuul
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
eureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eureka
eureka.instance.appname=microservice-gateway-zuul
zuul.routes.user-route.service-id=microservice-simple-provider-user
#zuul.ignoredServices=microservice-consumer-movie-ribbon-hystrix
zuul.routes.user-route.path=/user/**
#zuul.routes.user-route.url=http://localhost:7900/
ribbon.eureka.enabled=false
microservice-simple-provider-user.ribbon.listOfServers=http://localhost:7900/,http://localhost:7901/
?
總結
以上是生活随笔為你收集整理的Zuul指定Path+url以及指定可用的服务节点时如何负载均衡的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Zuul指定path+serviceid
- 下一篇: Zuul使用正则表达式指定路由规则