springcloud zuul路由网关 springcloud教程之zuul路由网关的实现

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

springcloud zuul路由网关 springcloud教程之zuul路由网关的实现

你若安好便是晴天   2021-04-02 我要评论

1.简介

当微服务对外提供接口访问时,并且有多个微服务,外部如何访问到具体的微服务?这时就可以使用网关的路由功能,依据url匹配将请求分别转发到不同的服务上

2.使用

zuul除了有转发功能,还有过滤功能,在网关层面可以对请求权限进行校验,token信息生成,设置token信息过期等等,并且可以将token保存到redis缓存中。

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>

application.yml文件中配置

spring:
 application:
  name: PublicGateWay //服务名
server:
 port: 8081 //端口

eureka:
 client:
  service-url:
   defaultZone: http://localhost:8083/eureka/ //注册中心地址
zuul:
 routes:
  api-user: //路由转发配置一
   path: /api-user/** //以/api-user/开头的请求都会转发到UserService服务中
   serviceId: UserService
  api-order:
   path: /api-common/**  //以/api-order/开头的请求都会转发到CommonIntegration服务中
   serviceId: CommonIntegration

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们