2019-06-17zuul 动态路由

1/bootstrap.yml, 因为要从配置中心读取文件( 从配置中心读取文件,配置文件名称必须bootsrap.yml, 不能用 application.yml。有一种说法是因为 bootstrap.yml 会在程序启动时知道要先从remote 读取信息,当然必要的jar 包别忘记引入)

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 9000 

#第一句设置hystrix 熔断时间

server:

  port: 1010

eureka:

  client:

    #eureka server的url 配置

    service-url:

      defaultZone: http://localhost:1005/eureka/

#是否注册到eureka

    register-with-eureka: true

    fetch-registry: true

spring:

  application:

    #应用名称,需要和git 上存的配置文件前缀一致

    name: zuul

#以下配置是从配置中心读取文件信息的配置

  cloud:

    config:

      discovery:

        enabled: true

        #配置中心名称

        service-id: config-server

    #git 上命名规则是 服务名称-环境.yml, 服务名称就是本服务名称,name:zuul, 环境          #prd,  所以这是读取zulul-prd.yml 的配置文件

      profile: prd

#开启所有监控中心接口

management:

  endpoints:

    web:

      exposure:

        include: "*"

#设置zuul调用超时时间。

ribbon:

    ReadTimeout: 60000

    SocketTimeout: 60000


#git 上的配置文件

git 配置文件
configserver

2、zuul 程序入口类


程序入口类

@RefreshScope 开启手动刷新方式。 手动刷新时 post 方式  访问 url: http://192.168.1.100:1010/actuator/refresh 即可。 整理中发现, 如果删除 git 配置中的 api-order 及其所有配置, 不重启,手动刷新后貌似仍能正常访问 api-order下的内容。 如果修改了api-order 的配置, 手动刷新后访问时就是用的最新配置。新增配置,手动刷新后也更新配置为最新git信息。

3、pom 文件

        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    4.0.0

   

        org.springframework.boot

        spring-boot-starter-parent

        2.1.5.RELEASE

       

   

    com.zbiti

    zuultest

    0.0.1-SNAPSHOT

    zuultest

    Demo project for Spring Boot

   

        1.8

        Greenwich.SR1

   

   

       

            org.springframework.boot

            spring-boot-starter-web

       

       

            org.springframework.cloud

            spring-cloud-starter-netflix-eureka-client

       

       

            org.springframework.cloud

            spring-cloud-starter-netflix-zuul

       

       

            org.springframework.boot

            spring-boot-starter-test

            test

       

       

            org.springframework.cloud

            spring-cloud-starter-config

       

       

            org.springframework.boot

            spring-boot-starter-actuator

            2.1.1.RELEASE

       

   

   

       

           

                org.springframework.cloud

                spring-cloud-dependencies

                ${spring-cloud.version}

                pom

                import

           

       

   

   

       

           

                org.springframework.boot

                spring-boot-maven-plugin

           

       

   

   

       

            spring-milestones

            Spring Milestones

            https://repo.spring.io/libs-milestone

           

                false

           

       

   



本地配置路由的又一个实例:

1、配置


zuul配置文件


简化版配置

也就是比如 eureka里注册的微服务名称 service-order, 不用再zuul里配置,默认的访问 {zuulip:port}/service-order/** , 就会访问的微服务service-order 的ip上去。

zuul配路由简化

2、访问


访问测试

你可能感兴趣的:(2019-06-17zuul 动态路由)