Zuul:包含了对请求的路由个过滤两个基本功能
其中路由功能负责将外部请求转发到具体的微服务实力上,是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验,服务聚合等功能的基础Zuul和Eureka进行整合,将Zuul自身注册为Eureka服务治理下的应用,同时从EUreka中获得其他微服务的消息,也即以后的访问微服务都是通过Zuul跳转后获得
注意:Zuul服务最终还是会注册进Eureka
配置Zuul
添加依赖
<!-- 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>
在主类上添加注解
/**
* @Description : ${END}
*/
@SpringBootApplication
@EnableZuulProxy
public class Zuul_Gateway_9527 {
public static void main(String[] args) {
SpringApplication.run(Zuul_Gateway_9527.class);
}
}
配置application.yaml
server:
port: 9527
spring:
application:
name: microservicecloud-zuul-gateway
eureka:
client:
service-url:
defaultZone: http://eurekaserver7001:7001/eureka,http://eurekaserver7002:7002/eureka,http://eurekaserver7003:7003/eureka
instance:
instance-id: gateway-9527.com
prefer-ip-address: true
info:
app.name: itheima.com-microcloud
company.name: itheima.com
build.artifactId: $project.artifactId$
build.version: $project.version$
#代理更改微服务的名称
zuul:
routes:
mydept.serviceId: providerdept #需要映射的微服务名称
mydept.path: /haha/** #映射之后微服务的名称
ignored-services: providerdept #忽略原微服务名称
|
|