1.概述
1.1 简介
Zuul包含了对请求的路由和过滤两个最主要的功能:
其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验、服务聚合等功能的基础.Zuul和Eureka进行整合,将Zuul自身注册为Eureka服务治理下的应用,同时从Eureka中获得其他微服务的消息,也即以后的访问微服务都是通过Zuul跳转后获得。
注意:Zuul服务最终还是会注册进Eureka
主要功能: 代理+路由+过滤
https://github.com/Netflix/zuul/wiki/Getting-Started
运用
2.1 pom
<!-- zuul路由网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
2.2 yml
server:
port: 9527
spring:
application:
name: microservicecloud-zuul-gateway
eureka:
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka
instance:
instance-id: gateway-9527.com
prefer-ip-address: true
2.3 hosts
127.0.0.1 myzuul.com
2.4 main
@SpringBootApplication
@EnableZuulProxy
public class Zuul_9527_StartSpringCloudApp
{
public static void main(String[] args)
{
SpringApplication.run(Zuul_9527_StartSpringCloudApp.class, args);
}
}
2.5 访问
http://localhost:8001/mydept/dept/get/1 普通访问,不用路由 http://myzuul.com:9527/microservicecloud-dept/dept/get/2 通过网关路由来访问(网关)[网关域名+Eureka注册的微服务地址+微服务中Rest访问]
2.6 服务名称路由
zuul:
#忽略(隐藏)某个服务
#ignored-services: microservicecloud-dept
#统一前缀
prefix: /allService
##忽略(隐藏)所有服务
ignored-services: "*"
routes:
mydept.serviceId: microservicecloud-dept
mydept.path: /mydept/**
– 总结于网络视频及网络文章