博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
《springcloud 二》微服务动态网关,网关集群
阅读量:4650 次
发布时间:2019-06-09

本文共 1774 字,大约阅读时间需要 5 分钟。

动态网关    实际上是网关和分布式配置中心的整合,通过post手动刷新,生效

 

动态网关

传统方式将路由规则配置在配置文件中,如果路由规则发生了改变,需要重启服务器。结合整合SpringCloud Config分布式配置中心,实现动态路由规则。

在git上创建一个文件service-zuul-dev.yml

### 配置网关反向代理    zuul:  routes:    api-a:     ### 以 /api-member/访问转发到会员服务      path: /api-member/**      serviceId: app-itmayiedu-member    api-b:        ### 以 /api-order/访问转发到订单服务      path: /api-order/**      serviceId: app-itmayiedu-order

Maven依赖信息

新增监控中心依赖信息

org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-config-client

application.yml

###服务注册地址eureka:  client:    serviceUrl:      defaultZone: http://localhost:8100/eureka/###api网关端口号      server:  port: 80###网关名称  spring:  application:    name: service-zuul  cloud:    config:    ####读取后缀      profile: dev      ####读取config-server注册地址      discovery:        service-id: config-server        enabled: true    ###默认服务读取eureka注册服务列表 默认间隔30秒###开启所有监控中心接口management:  endpoints:    web:      exposure:        include: "*"

项目启动

// zuul配置能够使用config实现实时更新    @RefreshScope    @ConfigurationProperties("zuul")    public ZuulProperties zuulProperties() {        return new ZuulProperties();    }

手动刷新接口

http://127.0.0.1/actuator/refresh 

 

网关集群

Zuul网关集群使用Nginx反向代理即可,保证每台网关配置数据相同。

upstream  backServer{        server 127.0.0.1:81;        server 127.0.0.1:82;    }    server {        listen       80;        server_name  wg.itmayiedu.com;       location / {            ### 指定上游服务器负载均衡服务器            proxy_pass http://backServer/;            index  index.html index.htm;        }    }

 

转载于:https://www.cnblogs.com/a1304908180/p/10677204.html

你可能感兴趣的文章