当前位置:网站首页>11.zuul路由网关
11.zuul路由网关
2022-07-27 02:37:00 【苦 糖 果】
1.概述
Zuul包含了对请求的路由和过滤两个最主要的功能:
其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验、服务聚合等功能的基础.
Zuul和Eureka进行整合,将Zuul自身注册为Eureka服务治理下的应用,同时从Eureka中获得其他微服务的消息,也即以后的访问微服务都是通过Zuul跳转后获得。
注意:Zuul服务最终还是会注册进Eureka
提供=代理+路由+过滤三大功能
github: https://github.com/Netflix/zuul/wiki/Getting-Started
2. 新建Module模块microservicecloud-zuul-gateway-9527
2.1 改pom
当不知道搭配使用哪个版本时,直接搜Dalston.SR1。
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- zuul路由网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<!-- actuator监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</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>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
2.2 改yml
server:
port: 9527
spring:
application:
name: microservicecloud-zuul-gateway
zuul:
prefix: /atguigu
ignored-services: "*" # 忽略真实服务名
routes:
mydept.serviceId: cloud-payment-service
mydept.path: /path/**
eureka:
client:
register-with-eureka: true
fetchRegistry: true
service-url:
defaultZone: http://localhost:7001/eureka
# defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版
instance:
instance-id: zullgateway9527
prefer-ip-address: true
lease-renewal-interval-in-seconds: 1
lease-expiration-duration-in-seconds: 2
2.3 启动类
@EnableZuulProxy:开启zuul网关代理
@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
@Slf4j
public class ZuulStartSpringCloudApp9527 {
public static void main(String[] args)
{
SpringApplication.run(ZuulStartSpringCloudApp9527.class, args);
log.info("===============ZuulStartSpringCloudApp9527启动成功===============");
}
}
2.4 路由访问映射规则
before
http://localhost:9527/atguigu/cloud-payment-service/payment/get/3
zuul:
routes:
mydept.serviceId: microservicecloud-dept
mydept.path: /mydept/**
after
http://localhost:9527/atguigu/path/payment/get/3
通过cloud-payment-service或者path都可以访问。
原真实服务名忽略:
ignored-services:单个具体,多个可以用"*"
设置统一公共前缀:
prefix: /atguigu
2.5 测试
启动cloud-eureka-server7001,启动cloud-provider-payment8001,启动microservicecloud-zuul-gateway-9527,将8001和9527都注册到eureka.
访问:http://localhost:9527/atguigu/path/payment/get/3 正常返回。
边栏推荐
- Plato farm is expected to further expand its ecosystem through elephant swap
- Characteristics and determination scheme of Worthington pectinase
- DNS record type and explanation of related terms
- Six determination methods of Worthington peroxidase activity
- C语言力扣第43题之字符串相乘。优化竖式
- Bean Validation原理篇--07
- 第六周复习
- Worthington papain dissociation system solution
- OC message mechanism
- flink cdc 到MySQL8没问题,到MySQL5读有问题,怎么办?
猜你喜欢

Digital analog 1232

STM32CubeMX学习笔记(41)——ETH接口+LwIP协议栈使用(DHCP)

222. Number of nodes of complete binary tree

FastBoot brush machine

小于等于K的最大子数组累加和

关于使用hyperbeach出现/bin/sh: 1: packr2: not found的解决方案

Maximum subarray cumulative sum less than or equal to K

面试题:String类中三种实例化对象的区别

Cocos game practice-04-collision detection and NPC rendering

VR全景人淘金“小心机”(上)
随机推荐
Bean Validation原理篇--07
mysql中case when返回多个字段处理方案
URDF_Xcaro
Two help points distribution brings to merchants
GetObject call timing of factorybean
真正意义上的数字零售应当具有更加丰富的内涵和意义
Connman introduction
分析一下CSDN大佬写的CAS,可重入锁, 非公平锁
Application, addition and deletion of B-tree
Smart pointer shared_ ptr、unique_ ptr、weak_ ptr
Kettle读取按行分割的文件
C语言入门实战(12):求自然常数e的值
Chapter 5 决策树和随机森林实践
这个FlinkCDC会监控数据库中所有的表?还是指定的表呢?我看后台日志,他是监控了所有表,如果监控
Characteristics and experimental suggestions of abbkine abfluor 488 cell apoptosis detection kit
Chapter 5 decision tree and random forest practice
Daffodils (day 78)
Food chain (day 79)
A. Parkway Walk
If the detailed explanation is generated according to the frame code