文章28 | 阅读 13240 | 点赞0
zuul包含了对外请求的路由和过滤两个最要的功能
其中路由功能负责将外部的请求转发到具体的微服务实例上,是实现外部访问统一入口基础而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验,服务聚合功能的基础Zuul和eureka进行整合,将Zuul自身注册为Eureka服务治理下的应用,同时从Eureka中获取到其他的微服务的消息,也即以后的访问微服务都是通过 Zuul跳后获得
Zuul还是会注册到Eureka里
1)创建一个 Z uul d的项目
依赖
<!-- 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>
pom 文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xxx</groupId>
<artifactId>microservicecloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>microservicecloud-zuul-8087</artifactId>
<dependencies>
<!-- 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>
<!-- actuator监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- hystrix容错 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- 日常标配 -->
<dependency>
<groupId>com.xxx</groupId>
<artifactId>microservicecloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- 热部署插件 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
</project>
server:
port: 8087
spring:
application:
name: microservicecloud-zuul
eureka:
client:
service-url:
defaultZone: http://euerka7001.com:7001/eureka/,http://euerka7002.com:7002/eureka/,http://euerka7003.com:7003/eureka/
instance:
instance-id: zuul8078.com
prefer-ip-address: true
zuul:
prefix: /com # 统一前缀
ignored-services: "*" # 隐藏所有的真实的微服务名
routes:
mydept.serviceId: microservicecloud-dept #真是的微服务名
mydept.path: /user/** #暴露自定义的名字
info:
app.name: com-xxx-xxx
company.name: www.baidu.com
build.artifactId: $project.artifactId$
build.version: $project.version$
启动项目 访问
Eureka(7001,7002,7003) 提供者(8083)zuul路由网关(80787)
提供者自测
使用Zuul路由网关 访问页面
在使用真实的 微服务的名字 就访问不到了
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_44520739/article/details/89473738
内容来源于网络,如有侵权,请联系作者删除!