zuul配置踩坑

需求描述,使用zuul作爲後臺網站的前置網關:

0代碼純配置。環境需求:eureka,springboot業務節點

1.添加負載均衡

需要加以下內容:

開啓負載均衡:

spring:
  cloud:
    loadbalancer:
      retry:
        enabled: true

開啓zuul負載均衡

zuul:
  ribbon:
      eager-load:
        enabled: true
        clients: datisweb
  routes:
    test:
      sensitiveHeaders: "*"  # 防止session發生變更
      path: /**
      serviceId: datisweb
      retryable: true
  ignored-services:  "*"
  retryable: true

設置異常後重試節點:

test:
  ribbon:
    ReadTimeout: 10000
    ConnectTimeout: 10000
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
    OkToRetryOnAllOperations: true
    MaxAutoRetriesNextServer: 2    #重試節點次數
    MaxAutoRetries: 0    #單節點重試次數

當然這裏請注意除了以上外還需引入:

		<dependency>
			<groupId>org.springframework.retry</groupId>
			<artifactId>spring-retry</artifactId>
		</dependency>

如果不加,以上的重試機制將不會起作用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章