1. 程式人生 > 其它 >SpringCloud nacos、Zuul和 gateway閘道器配置

SpringCloud nacos、Zuul和 gateway閘道器配置

技術標籤:Spring Cloud

一、框架搭建

(1)專案結構

micro-service 服務提供者
zuul-gateway zuul閘道器
springcloud-gatewaygateway閘道器

(2)環境

nacos 1.4.1

springboot 2.1.9

springcloud2.1.3

二、專案配置application.yaml

(1)micro-service

spring:
  application:
    name: micro-service
  profiles:
    active: dev
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
    default-property-inclusion: ALWAYS
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

server:
  port: 8081

(2)zuul-gateway

spring:
  application:
    name: zuul-gateway
  profiles:
    active: dev
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
    default-property-inclusion: ALWAYS
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848


server:
  port: 8082

zuul:
  strip-prefix: true #轉發路徑截斷匹配字首
#  prefix: "/api"
  add-proxy-headers: false
  set-content-length: true
  semaphore:
    max-semaphores: 600

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 120000
ribbon:
  ReadTimeout: 240000
  ConnectTimeout: 2000
  MaxAutoRetries: 0
  MaxAutoRetriesNextServer: 1
  eager-load:
    enabled: true
    clients: micro-service

(3)springcloud-gateway

spring:
  application:
    name: springcloud-gateway
  profiles:
    active: dev
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
    default-property-inclusion: ALWAYS
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
      httpclient:
        connect-timeout: 60000
        response-timeout: 5s
      routes:
      - id: micro-service1
        uri: lb://micro-service
        predicates:
        - Path=/micro-service1/**
        filters:
        - StripPrefix=1
server:
  port: 8083


hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 120000
ribbon:
  ReadTimeout: 240000
  ConnectTimeout: 2000
  MaxAutoRetries: 0
  MaxAutoRetriesNextServer: 1
  eager-load:
    enabled: true
    clients: micro-service

三、專案地址

https://github.com/90duc/springcloud-nacos